[libcamera-devel,v3,09/12] android: camera_stream: Add thread safety annotation
diff mbox series

Message ID 20211130155600.2203123-10-hiroh@chromium.org
State Superseded
Headers show
Series
  • Introduce clang thread safety annotations
Related show

Commit Message

Hirokazu Honda Nov. 30, 2021, 3:55 p.m. UTC
This applies clang thread safety annotation to CameraStream.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
---
 src/android/camera_stream.cpp | 2 +-
 src/android/camera_stream.h   | 9 ++++++---
 2 files changed, 7 insertions(+), 4 deletions(-)

Patch
diff mbox series

diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp
index 2181d094..ae659808 100644
--- a/src/android/camera_stream.cpp
+++ b/src/android/camera_stream.cpp
@@ -275,7 +275,7 @@  void CameraStream::PostProcessorWorker::run()
 	MutexLocker locker(mutex_);
 
 	while (1) {
-		cv_.wait(locker, [&] {
+		cv_.wait(locker, [&]() LIBCAMERA_TSA_REQUIRES(mutex_) {
 			return state_ != State::Running || !requests_.empty();
 		});
 
diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h
index e4eb953a..6737bd2d 100644
--- a/src/android/camera_stream.h
+++ b/src/android/camera_stream.h
@@ -15,6 +15,7 @@ 
 
 #include <libcamera/base/mutex.h>
 #include <libcamera/base/thread.h>
+#include <libcamera/base/thread_annotations.h>
 
 #include <libcamera/camera.h>
 #include <libcamera/framebuffer.h>
@@ -155,8 +156,10 @@  private:
 		libcamera::Mutex mutex_;
 		libcamera::ConditionVariable cv_;
 
-		std::queue<Camera3RequestDescriptor::StreamBuffer *> requests_;
-		State state_ = State::Stopped;
+		std::queue<Camera3RequestDescriptor::StreamBuffer *> requests_
+			LIBCAMERA_TSA_GUARDED_BY(mutex_);
+
+		State state_ LIBCAMERA_TSA_GUARDED_BY(mutex_) = State::Stopped;
 	};
 
 	int waitFence(int fence);
@@ -168,7 +171,7 @@  private:
 	const unsigned int index_;
 
 	std::unique_ptr<libcamera::FrameBufferAllocator> allocator_;
-	std::vector<libcamera::FrameBuffer *> buffers_;
+	std::vector<libcamera::FrameBuffer *> buffers_ LIBCAMERA_TSA_GUARDED_BY(mutex_);
 	/*
 	 * The class has to be MoveConstructible as instances are stored in
 	 * an std::vector in CameraDevice.