[libcamera-devel,2/7] libcamera: base: thread: Protect exitCode by mutex in exit()
diff mbox series

Message ID 20211203164619.1541033-3-hiroh@chromium.org
State New
Headers show
Series
  • Apply clang thread safety annotation libcamera-core and v4l2
Related show

Commit Message

Hirokazu Honda Dec. 3, 2021, 4:46 p.m. UTC
This fixes the bug that Thread::exit() accesses data_->exitCode
without acquiring a lock.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
---
 src/libcamera/base/thread.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp
index 6bda9d14..abd33a83 100644
--- a/src/libcamera/base/thread.cpp
+++ b/src/libcamera/base/thread.cpp
@@ -390,9 +390,11 @@  void Thread::finishThread()
  *
  * \context This function is \threadsafe.
  */
-void Thread::exit(int code)
+void Thread::exitint code)
 {
+	data_->mutex_.lock();
 	data_->exitCode_ = code;
+	data_->mutex_.unlock();
 	data_->exit_.store(true, std::memory_order_release);
 
 	EventDispatcher *dispatcher = data_->dispatcher_.load(std::memory_order_relaxed);