trantor
Non-blocking I/O cross-platform TCP network library, using C++14
Loading...
Searching...
No Matches
SerialTaskQueue.h
1
14
15#pragma once
16
17#include "TaskQueue.h"
19#include <trantor/exports.h>
20#include <string>
21#include <queue>
22#include <mutex>
23#include <atomic>
24namespace trantor
25{
31class TRANTOR_EXPORT SerialTaskQueue : public TaskQueue
32{
33 public:
39 virtual void runTaskInQueue(const std::function<void()> &task);
40 virtual void runTaskInQueue(std::function<void()> &&task);
41
47 virtual std::string getName() const
48 {
49 return queueName_;
50 };
51
57
58 SerialTaskQueue() = delete;
59
65 explicit SerialTaskQueue(const std::string &name);
66
67 virtual ~SerialTaskQueue();
68
69 /* clang-format off */
77 [[deprecated("Use isRunningTask instead")]]
79 {
80 return isRunningTask();
81 }
82 /* clang-format on */
83
91 {
92 return loopThread_.getLoop()
93 ? loopThread_.getLoop()->isCallingFunctions()
94 : false;
95 }
96
102 size_t getTaskCount();
103
108 void stop();
109
110 protected:
111 std::string queueName_;
112 EventLoopThread loopThread_;
113 bool stop_{false};
114};
115} // namespace trantor
This class represents an event loop thread.
Definition EventLoopThread.h:33
void waitAllTasksFinished()
Wait until all tasks in the queue are finished.
SerialTaskQueue(const std::string &name)
Construct a new serial task queue instance.
virtual std::string getName() const
Get the name of the queue.
Definition SerialTaskQueue.h:47
bool isRuningTask()
Check whether a task is running in the queue.
Definition SerialTaskQueue.h:78
void stop()
Stop the queue.
bool isRunningTask()
Check whether a task is running in the queue.
Definition SerialTaskQueue.h:90
virtual void runTaskInQueue(const std::function< void()> &task)
Run a task in the queue.
size_t getTaskCount()
Get the number of tasks in the queue.
This class is a pure virtual class that can be implemented as a SerialTaskQueue or a ConcurrentTaskQu...
Definition TaskQueue.h:29
Definition EventLoop.h:34