[libcamera-devel] [PATCH 2/7] libcamera: base: thread: Protect exitCode by mutex in exit()
Hirokazu Honda
hiroh at chromium.org
Fri Dec 3 17:46:14 CET 2021
This fixes the bug that Thread::exit() accesses data_->exitCode
without acquiring a lock.
Signed-off-by: Hirokazu Honda <hiroh at chromium.org>
---
src/libcamera/base/thread.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
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);
--
2.34.0.384.gca35af8252-goog
More information about the libcamera-devel
mailing list