File tree Expand file tree Collapse file tree 2 files changed +13
-16
lines changed Expand file tree Collapse file tree 2 files changed +13
-16
lines changed Original file line number Diff line number Diff line change @@ -165,15 +165,6 @@ void EventLoop::quit()
165
165
{
166
166
quit_.store (true , std::memory_order_release);
167
167
168
- Func f;
169
- while (funcsOnQuit_.dequeue (f))
170
- {
171
- f ();
172
- }
173
-
174
- // There is a chance that loop() just executes while(!quit_) and exits,
175
- // then EventLoop destructs, then we are accessing an invalid object.
176
- // Can be fixed using mutex_ in both places.
177
168
if (!isInLoopThread ())
178
169
{
179
170
wakeup ();
@@ -205,12 +196,18 @@ void EventLoop::loop()
205
196
currentActiveChannel_ = *it;
206
197
currentActiveChannel_->handleEvent ();
207
198
}
208
- currentActiveChannel_ = NULL ;
199
+ currentActiveChannel_ = nullptr ;
209
200
eventHandling_ = false ;
210
201
// std::cout << "looping" << endl;
211
202
doRunInLoopFuncs ();
212
203
}
213
204
looping_.store (false , std::memory_order_release);
205
+
206
+ Func f;
207
+ while (funcsOnQuit_.dequeue (f))
208
+ {
209
+ f ();
210
+ }
214
211
}
215
212
void EventLoop::abortNotInLoopThread ()
216
213
{
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ EventLoopThread::EventLoopThread(const std::string &threadName)
27
27
auto f = promiseForLoopPointer_.get_future ();
28
28
loop_ = f.get ();
29
29
}
30
+
30
31
EventLoopThread::~EventLoopThread ()
31
32
{
32
33
run ();
@@ -39,28 +40,27 @@ EventLoopThread::~EventLoopThread()
39
40
thread_.join ();
40
41
}
41
42
}
42
- // void EventLoopThread::stop() {
43
- // if(loop_)
44
- // loop_->quit();
45
- // }
43
+
46
44
void EventLoopThread::wait ()
47
45
{
48
46
thread_.join ();
49
47
}
48
+
50
49
void EventLoopThread::loopFuncs ()
51
50
{
52
51
#ifdef __linux__
53
52
::prctl (PR_SET_NAME, loopThreadName_.c_str());
54
53
#endif
55
- EventLoop loop;
54
+ thread_local static EventLoop loop;
56
55
loop.queueInLoop ([this ]() { promiseForLoop_.set_value (1 ); });
57
56
promiseForLoopPointer_.set_value (&loop);
58
57
auto f = promiseForRun_.get_future ();
59
58
(void )f.get ();
60
59
loop.loop ();
61
60
// LOG_DEBUG << "loop out";
62
- loop_ = NULL ;
61
+ loop_ = nullptr ;
63
62
}
63
+
64
64
void EventLoopThread::run ()
65
65
{
66
66
std::call_once (once_, [this ]() {
You can’t perform that action at this time.
0 commit comments