-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Description
EventLoop* EventLoopThread::startLoop()
{
assert(!thread_.started());
thread_.start();
EventLoop* loop = NULL;
{
MutexLockGuard lock(mutex_);
while (loop_ == NULL)
{
cond_.wait();
}
loop = loop_;
}
return loop;
}
void EventLoopThread::threadFunc()
{
EventLoop loop;
if (callback_)
{
callback_(&loop);
}
{
MutexLockGuard lock(mutex_);
loop_ = &loop;
cond_.notify();
}
loop.loop();
//assert(exiting_);
MutexLockGuard lock(mutex_);
loop_ = NULL;
}EventLoopThread::startLoop()是否可以实现为下面的方式?
EventLoop* EventLoopThread::startLoop() {
thread_.start();
std::unique_lock lock(mutex_);
cv_.wait(lock, [this]() { return loop_ != nullptr; });
return loop_;
}望赐教,谢谢
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels