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

Message ID 20211130155600.2203123-12-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 CameraDevice.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/android/camera_device.h | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

Patch
diff mbox series

diff --git a/src/android/camera_device.h b/src/android/camera_device.h
index a945f5de..2083dac1 100644
--- a/src/android/camera_device.h
+++ b/src/android/camera_device.h
@@ -18,6 +18,7 @@ 
 #include <libcamera/base/log.h>
 #include <libcamera/base/message.h>
 #include <libcamera/base/mutex.h>
+#include <libcamera/base/thread_annotations.h>
 
 #include <libcamera/camera.h>
 #include <libcamera/framebuffer.h>
@@ -82,7 +83,7 @@  private:
 		Running,
 	};
 
-	void stop();
+	void stop() LIBCAMERA_TSA_EXCLUDES(stateMutex_);
 
 	std::unique_ptr<libcamera::FrameBuffer>
 	createFrameBuffer(const buffer_handle_t camera3buffer,
@@ -94,8 +95,9 @@  private:
 	void notifyError(uint32_t frameNumber, camera3_stream_t *stream,
 			 camera3_error_msg_code code) const;
 	int processControls(Camera3RequestDescriptor *descriptor);
-	void completeDescriptor(Camera3RequestDescriptor *descriptor);
-	void sendCaptureResults();
+	void completeDescriptor(Camera3RequestDescriptor *descriptor)
+		LIBCAMERA_TSA_EXCLUDES(descriptorsMutex_);
+	void sendCaptureResults() LIBCAMERA_TSA_REQUIRES(descriptorsMutex_);
 	void setBufferStatus(Camera3RequestDescriptor::StreamBuffer &buffer,
 			     Camera3RequestDescriptor::Status status);
 	std::unique_ptr<CameraMetadata> getResultMetadata(
@@ -107,7 +109,7 @@  private:
 	CameraWorker worker_;
 
 	libcamera::Mutex stateMutex_; /* Protects access to the camera state. */
-	State state_;
+	State state_ LIBCAMERA_TSA_GUARDED_BY(stateMutex_);
 
 	std::shared_ptr<libcamera::Camera> camera_;
 	std::unique_ptr<libcamera::CameraConfiguration> config_;
@@ -118,8 +120,9 @@  private:
 
 	std::vector<CameraStream> streams_;
 
-	libcamera::Mutex descriptorsMutex_; /* Protects descriptors_. */
-	std::queue<std::unique_ptr<Camera3RequestDescriptor>> descriptors_;
+	libcamera::Mutex descriptorsMutex_ LIBCAMERA_TSA_ACQUIRED_AFTER(stateMutex_);
+	std::queue<std::unique_ptr<Camera3RequestDescriptor>> descriptors_
+		LIBCAMERA_TSA_GUARDED_BY(descriptorsMutex_);
 
 	std::string maker_;
 	std::string model_;