trantor
Non-blocking I/O cross-platform TCP network library, using C++14
Toggle main menu visibility
Loading...
Searching...
No Matches
EventLoopThread.h
Go to the documentation of this file.
1
14
15
#pragma once
16
17
#include <trantor/net/EventLoop.h>
18
#include <
trantor/utils/NonCopyable.h
>
19
#include <trantor/exports.h>
20
#include <mutex>
21
#include <thread>
22
#include <memory>
23
#include <condition_variable>
24
#include <future>
25
26
namespace
trantor
27
{
32
class
TRANTOR_EXPORT EventLoopThread : NonCopyable
33
{
34
public
:
35
explicit
EventLoopThread(
const
std::string &threadName =
"EventLoopThread"
);
36
~EventLoopThread();
37
42
void
wait
();
43
49
EventLoop
*
getLoop
()
const
50
{
51
return
loop_.get();
52
}
53
59
void
run
();
60
61
private
:
62
// With C++20, use std::atomic<std::shared_ptr<EventLoop>>
63
std::shared_ptr<EventLoop> loop_;
64
std::mutex loopMutex_;
65
66
std::string loopThreadName_;
67
void
loopFuncs();
68
std::promise<std::shared_ptr<EventLoop>> promiseForLoopPointer_;
69
std::promise<int> promiseForRun_;
70
std::promise<int> promiseForLoop_;
71
std::once_flag once_;
72
std::thread thread_;
73
};
74
75
}
// namespace trantor
NonCopyable.h
trantor::EventLoopThread::wait
void wait()
Wait for the event loop to exit.
trantor::EventLoopThread::getLoop
EventLoop * getLoop() const
Get the pointer of the event loop of the thread.
Definition
EventLoopThread.h:49
trantor::EventLoopThread::run
void run()
Run the event loop of the thread. This method doesn't block the current thread.
trantor::EventLoop
As the name implies, this class represents an event loop that runs in a particular thread....
Definition
EventLoop.h:56
trantor
Definition
EventLoop.h:34
trantor
net
EventLoopThread.h
Generated by
1.17.0