From cd9e72944e55b5eb3526e5b0befe00940630a0ac Mon Sep 17 00:00:00 2001 From: Hirokazu Honda Date: Thu, 3 Nov 2022 18:50:39 +0530 Subject: libcamera: camera_manager: Apply clang thread safety annotation This annotates member functions and variables of CameraManager::Private by clang thread safety annotations. Signed-off-by: Hirokazu Honda Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart Reviewed-by: Umang Jain --- src/libcamera/camera_manager.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 2c100c24..b1785f75 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -42,8 +42,8 @@ public: int start(); void addCamera(std::shared_ptr camera, - const std::vector &devnums); - void removeCamera(Camera *camera); + const std::vector &devnums) LIBCAMERA_TSA_EXCLUDES(mutex_); + void removeCamera(Camera *camera) LIBCAMERA_TSA_EXCLUDES(mutex_); /* * This mutex protects @@ -52,8 +52,8 @@ public: * - cameras_ and camerasByDevnum_ after initialization */ mutable Mutex mutex_; - std::vector> cameras_; - std::map> camerasByDevnum_; + std::vector> cameras_ LIBCAMERA_TSA_GUARDED_BY(mutex_); + std::map> camerasByDevnum_ LIBCAMERA_TSA_GUARDED_BY(mutex_); protected: void run() override; @@ -61,11 +61,11 @@ protected: private: int init(); void createPipelineHandlers(); - void cleanup(); + void cleanup() LIBCAMERA_TSA_EXCLUDES(mutex_); ConditionVariable cv_; - bool initialized_; - int status_; + bool initialized_ LIBCAMERA_TSA_GUARDED_BY(mutex_); + int status_ LIBCAMERA_TSA_GUARDED_BY(mutex_); std::unique_ptr enumerator_; @@ -87,7 +87,9 @@ int CameraManager::Private::start() { MutexLocker locker(mutex_); - cv_.wait(locker, [&] { return initialized_; }); + cv_.wait(locker, [&]() LIBCAMERA_TSA_REQUIRES(mutex_) { + return initialized_; + }); status = status_; } @@ -178,7 +180,11 @@ void CameraManager::Private::cleanup() * process deletion requests from the thread's message queue as the event * loop is not in action here. */ - cameras_.clear(); + { + MutexLocker locker(mutex_); + cameras_.clear(); + } + dispatchMessages(Message::Type::DeferredDelete); enumerator_.reset(nullptr); -- cgit v1.2.1