diff options
author | Adrian Salido <salidoa@google.com> | 2017-04-25 20:53:11 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-04-25 20:53:11 +0000 |
commit | 884ae6f0d789f3506bc5bf838c6dc33faa46d9c8 (patch) | |
tree | 23cdb028b995a9e712cab1c9cf19d68ce4e141d5 | |
parent | fbce8b7ebcac3b86eab400a6b38f6cf1e81a1b1e (diff) | |
parent | d7a6c091e4ff5a12f76bc9c0bbde159cb59ba16a (diff) | |
download | drm_hwcomposer-884ae6f0d789f3506bc5bf838c6dc33faa46d9c8.tar.gz |
drm_hwcomposer: avoid potential race condition between worker init and exit am: ba494c8efc
am: d7a6c091e4
Change-Id: I3a0400378f8a1b2c008e6b8494e1fac0788acef2
-rw-r--r-- | worker.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -30,21 +30,23 @@ Worker::~Worker() { } int Worker::InitWorker() { + std::lock_guard<std::mutex> lk(mutex_); if (initialized()) return -EALREADY; thread_ = std::unique_ptr<std::thread>( new std::thread(&Worker::InternalRoutine, this)); initialized_ = true; + exit_ = false; return 0; } void Worker::Exit() { + std::unique_lock<std::mutex> lk(mutex_); + exit_ = true; if (initialized()) { - Lock(); - exit_ = true; - Unlock(); + lk.unlock(); cond_.notify_all(); thread_->join(); initialized_ = false; @@ -68,7 +70,7 @@ int Worker::WaitForSignalOrExitLocked(int64_t max_nanoseconds) { if (should_exit()) ret = -EINTR; - // release leaves lock unlocked when returning + // release leaves mutex locked when going out of scope lk.release(); return ret; |