[libcamera-devel,3/7] libcamera: base: thread: Apply clang thread safety annotation
diff mbox series

Message ID 20211203164619.1541033-4-hiroh@chromium.org
State Accepted
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 annotates member variables of ThreadData by clang thread
safety annotations.

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

Patch
diff mbox series

diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp
index abd33a83..205f3d1b 100644
--- a/src/libcamera/base/thread.cpp
+++ b/src/libcamera/base/thread.cpp
@@ -151,7 +151,7 @@  private:
 	friend class ThreadMain;
 
 	Thread *thread_;
-	bool running_;
+	bool running_ LIBCAMERA_TSA_GUARDED_BY(mutex_);
 	pid_t tid_;
 
 	Mutex mutex_;
@@ -160,7 +160,7 @@  private:
 
 	ConditionVariable cv_;
 	std::atomic<bool> exit_;
-	int exitCode_;
+	int exitCode_ LIBCAMERA_TSA_GUARDED_BY(mutex_);
 
 	MessageQueue messages_;
 };
@@ -390,7 +390,7 @@  void Thread::finishThread()
  *
  * \context This function is \threadsafe.
  */
-void Thread::exitint code)
+void Thread::exit(int code)
 {
 	data_->mutex_.lock();
 	data_->exitCode_ = code;
@@ -424,11 +424,19 @@  bool Thread::wait(utils::duration duration)
 	{
 		MutexLocker locker(data_->mutex_);
 
-		if (duration == utils::duration::max())
-			data_->cv_.wait(locker, [&]() { return !data_->running_; });
-		else
-			hasFinished = data_->cv_.wait_for(locker, duration,
-							  [&]() { return !data_->running_; });
+		if (duration == utils::duration::max()) {
+			data_->cv_.wait(
+				locker,
+				[&]() LIBCAMERA_TSA_REQUIRES(data_->mutex_) {
+					return !data_->running_;
+				});
+		} else {
+			hasFinished = data_->cv_.wait_for(
+				locker, duration,
+				[&]() LIBCAMERA_TSA_REQUIRES(data_->mutex_) {
+					return !data_->running_;
+				});
+		}
 	}
 
 	if (thread_.joinable())