diff options
author | Adrian Salido <salidoa@google.com> | 2017-04-25 21:11:53 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-04-25 21:11:53 +0000 |
commit | a3dc0d2f2acff5ed74f8ad5e0cc9195c8225e5da (patch) | |
tree | 715f3f024c258a928abdd3ee36ae25b6bd4081a4 | |
parent | 8035e239065d0d8c9059fb4d35108951a8c8dc9b (diff) | |
parent | 39c391a036f450728bbdc032d4b9fd5c1101e59e (diff) | |
download | drm_hwcomposer-a3dc0d2f2acff5ed74f8ad5e0cc9195c8225e5da.tar.gz |
drm_hwcomposer: avoid potential race condition between worker init and exit am: ba494c8efc am: d7a6c091e4 am: 884ae6f0d7 am: 64cacd753b
am: 39c391a036
Change-Id: Ibfc45d114fa1f4052b79d9f2ffa175eb6d538158
-rw-r--r-- | worker.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -30,6 +30,7 @@ Worker::~Worker() { } int Worker::InitWorker() { + std::lock_guard<std::mutex> lk(mutex_); if (initialized()) return -EALREADY; @@ -42,10 +43,10 @@ int Worker::InitWorker() { } 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; @@ -69,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; |