trantor
Non-blocking I/O cross-platform TCP network library, using C++14
Toggle main menu visibility
Loading...
Searching...
No Matches
ConcurrentTaskQueue.h
Go to the documentation of this file.
1
14
15
#pragma once
16
17
#include <
trantor/utils/TaskQueue.h
>
18
#include <trantor/exports.h>
19
#include <list>
20
#include <memory>
21
#include <vector>
22
#include <queue>
23
#include <string>
24
25
namespace
trantor
26
{
32
class
TRANTOR_EXPORT
ConcurrentTaskQueue
:
public
TaskQueue
33
{
34
public
:
41
ConcurrentTaskQueue
(
size_t
threadNum,
const
std::string &name);
42
48
virtual
void
runTaskInQueue
(
const
std::function<
void
()> &task);
49
virtual
void
runTaskInQueue
(std::function<
void
()> &&task);
50
56
virtual
std::string
getName
()
const
57
{
58
return
queueName_;
59
};
60
66
size_t
getTaskCount
();
67
72
void
stop
();
73
74
~ConcurrentTaskQueue
();
75
76
private
:
77
size_t
queueCount_;
78
std::string queueName_;
79
80
std::queue<std::function<void()>> taskQueue_;
81
std::vector<std::thread> threads_;
82
83
std::mutex taskMutex_;
84
std::condition_variable taskCond_;
85
std::atomic_bool stop_;
86
void
queueFunc(
int
queueNum);
87
};
88
89
}
// namespace trantor
TaskQueue.h
trantor::ConcurrentTaskQueue::getTaskCount
size_t getTaskCount()
Get the number of tasks to be executed in the queue.
trantor::ConcurrentTaskQueue::ConcurrentTaskQueue
ConcurrentTaskQueue(size_t threadNum, const std::string &name)
Construct a new concurrent task queue instance.
trantor::ConcurrentTaskQueue::stop
void stop()
Stop all threads in the queue.
trantor::ConcurrentTaskQueue::getName
virtual std::string getName() const
Get the name of the queue.
Definition
ConcurrentTaskQueue.h:56
trantor::ConcurrentTaskQueue::runTaskInQueue
virtual void runTaskInQueue(const std::function< void()> &task)
Run a task in the queue.
trantor::TaskQueue
This class is a pure virtual class that can be implemented as a SerialTaskQueue or a ConcurrentTaskQu...
Definition
TaskQueue.h:29
trantor
Definition
EventLoop.h:34
trantor
utils
ConcurrentTaskQueue.h
Generated by
1.17.0