[libcamera-devel,v2,02/11] android: Consolidate mutex classes to Mutex and MutexLocker
diff mbox series

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

Commit Message

Hirokazu Honda Nov. 29, 2021, 11:44 a.m. UTC
std::mutex and std::unique_lcok are used in android directories,
mixing Mutex and MutexLocker. This consolidates them to Mutex
and MutexLocker.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
---
 src/android/camera_hal_manager.h |  6 ++----
 src/android/camera_request.h     |  4 ++--
 src/android/camera_stream.cpp    | 12 ++++++------
 src/android/camera_stream.h      |  2 +-
 4 files changed, 11 insertions(+), 13 deletions(-)

Comments

Laurent Pinchart Nov. 30, 2021, 4:05 a.m. UTC | #1
Hi Hiro,

Thank you for the patch.

On Mon, Nov 29, 2021 at 08:44:44PM +0900, Hirokazu Honda wrote:
> std::mutex and std::unique_lcok are used in android directories,
> mixing Mutex and MutexLocker. This consolidates them to Mutex
> and MutexLocker.
> 
> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/android/camera_hal_manager.h |  6 ++----
>  src/android/camera_request.h     |  4 ++--
>  src/android/camera_stream.cpp    | 12 ++++++------
>  src/android/camera_stream.h      |  2 +-
>  4 files changed, 11 insertions(+), 13 deletions(-)
> 
> diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h
> index 192f2fc5..c07684a1 100644
> --- a/src/android/camera_hal_manager.h
> +++ b/src/android/camera_hal_manager.h
> @@ -18,6 +18,7 @@
>  #include <system/camera_metadata.h>
>  
>  #include <libcamera/base/class.h>
> +#include <libcamera/base/thread.h>
>  
>  #include <libcamera/camera_manager.h>
>  
> @@ -44,9 +45,6 @@ public:
>  private:
>  	LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraHalManager)
>  
> -	using Mutex = std::mutex;
> -	using MutexLocker = std::unique_lock<std::mutex>;
> -
>  	static constexpr unsigned int firstExternalCameraId_ = 1000;
>  
>  	CameraHalManager();
> @@ -64,7 +62,7 @@ private:
>  	const camera_module_callbacks_t *callbacks_;
>  	std::vector<std::unique_ptr<CameraDevice>> cameras_;
>  	std::map<std::string, unsigned int> cameraIdsMap_;
> -	Mutex mutex_;
> +	libcamera::Mutex mutex_;
>  
>  	unsigned int numInternalCameras_;
>  	unsigned int nextExternalCameraId_;
> diff --git a/src/android/camera_request.h b/src/android/camera_request.h
> index f3cb6d64..88d501a8 100644
> --- a/src/android/camera_request.h
> +++ b/src/android/camera_request.h
> @@ -9,10 +9,10 @@
>  
>  #include <map>
>  #include <memory>
> -#include <mutex>
>  #include <vector>
>  
>  #include <libcamera/base/class.h>
> +#include <libcamera/base/thread.h>
>  
>  #include <libcamera/camera.h>
>  #include <libcamera/framebuffer.h>
> @@ -58,7 +58,7 @@ public:
>  
>  	/* Keeps track of streams requiring post-processing. */
>  	std::map<CameraStream *, StreamBuffer *> pendingStreamsToProcess_;
> -	std::mutex streamsProcessMutex_;
> +	libcamera::Mutex streamsProcessMutex_;
>  
>  	Camera3RequestDescriptor(libcamera::Camera *camera,
>  				 const camera3_capture_request_t *camera3Request);
> diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp
> index 9023c13c..5a62b7cd 100644
> --- a/src/android/camera_stream.cpp
> +++ b/src/android/camera_stream.cpp
> @@ -119,7 +119,7 @@ int CameraStream::configure()
>  
>  	if (type_ == Type::Internal) {
>  		allocator_ = std::make_unique<FrameBufferAllocator>(cameraDevice_->camera());
> -		mutex_ = std::make_unique<std::mutex>();
> +		mutex_ = std::make_unique<Mutex>();
>  
>  		int ret = allocator_->allocate(stream());
>  		if (ret < 0)
> @@ -208,7 +208,7 @@ FrameBuffer *CameraStream::getBuffer()
>  	if (!allocator_)
>  		return nullptr;
>  
> -	std::lock_guard<std::mutex> locker(*mutex_);
> +	MutexLocker locker(*mutex_);
>  
>  	if (buffers_.empty()) {
>  		LOG(HAL, Error) << "Buffer underrun";
> @@ -226,7 +226,7 @@ void CameraStream::putBuffer(FrameBuffer *buffer)
>  	if (!allocator_)
>  		return;
>  
> -	std::lock_guard<std::mutex> locker(*mutex_);
> +	MutexLocker locker(*mutex_);
>  
>  	buffers_.push_back(buffer);
>  }
> @@ -239,7 +239,7 @@ CameraStream::PostProcessorWorker::PostProcessorWorker(PostProcessor *postProces
>  CameraStream::PostProcessorWorker::~PostProcessorWorker()
>  {
>  	{
> -		libcamera::MutexLocker lock(mutex_);
> +		MutexLocker lock(mutex_);
>  		state_ = State::Stopped;
>  	}
>  
> @@ -250,7 +250,7 @@ CameraStream::PostProcessorWorker::~PostProcessorWorker()
>  void CameraStream::PostProcessorWorker::start()
>  {
>  	{
> -		libcamera::MutexLocker lock(mutex_);
> +		MutexLocker lock(mutex_);
>  		ASSERT(state_ != State::Running);
>  		state_ = State::Running;
>  	}
> @@ -308,7 +308,7 @@ void CameraStream::PostProcessorWorker::run()
>  
>  void CameraStream::PostProcessorWorker::flush()
>  {
> -	libcamera::MutexLocker lock(mutex_);
> +	MutexLocker lock(mutex_);
>  	state_ = State::Flushing;
>  	lock.unlock();
>  
> diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h
> index e4808369..c127a0e4 100644
> --- a/src/android/camera_stream.h
> +++ b/src/android/camera_stream.h
> @@ -173,7 +173,7 @@ private:
>  	 * The class has to be MoveConstructible as instances are stored in
>  	 * an std::vector in CameraDevice.
>  	 */
> -	std::unique_ptr<std::mutex> mutex_;
> +	std::unique_ptr<libcamera::Mutex> mutex_;
>  	std::unique_ptr<PostProcessor> postProcessor_;
>  
>  	std::unique_ptr<PostProcessorWorker> worker_;

Patch
diff mbox series

diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h
index 192f2fc5..c07684a1 100644
--- a/src/android/camera_hal_manager.h
+++ b/src/android/camera_hal_manager.h
@@ -18,6 +18,7 @@ 
 #include <system/camera_metadata.h>
 
 #include <libcamera/base/class.h>
+#include <libcamera/base/thread.h>
 
 #include <libcamera/camera_manager.h>
 
@@ -44,9 +45,6 @@  public:
 private:
 	LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraHalManager)
 
-	using Mutex = std::mutex;
-	using MutexLocker = std::unique_lock<std::mutex>;
-
 	static constexpr unsigned int firstExternalCameraId_ = 1000;
 
 	CameraHalManager();
@@ -64,7 +62,7 @@  private:
 	const camera_module_callbacks_t *callbacks_;
 	std::vector<std::unique_ptr<CameraDevice>> cameras_;
 	std::map<std::string, unsigned int> cameraIdsMap_;
-	Mutex mutex_;
+	libcamera::Mutex mutex_;
 
 	unsigned int numInternalCameras_;
 	unsigned int nextExternalCameraId_;
diff --git a/src/android/camera_request.h b/src/android/camera_request.h
index f3cb6d64..88d501a8 100644
--- a/src/android/camera_request.h
+++ b/src/android/camera_request.h
@@ -9,10 +9,10 @@ 
 
 #include <map>
 #include <memory>
-#include <mutex>
 #include <vector>
 
 #include <libcamera/base/class.h>
+#include <libcamera/base/thread.h>
 
 #include <libcamera/camera.h>
 #include <libcamera/framebuffer.h>
@@ -58,7 +58,7 @@  public:
 
 	/* Keeps track of streams requiring post-processing. */
 	std::map<CameraStream *, StreamBuffer *> pendingStreamsToProcess_;
-	std::mutex streamsProcessMutex_;
+	libcamera::Mutex streamsProcessMutex_;
 
 	Camera3RequestDescriptor(libcamera::Camera *camera,
 				 const camera3_capture_request_t *camera3Request);
diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp
index 9023c13c..5a62b7cd 100644
--- a/src/android/camera_stream.cpp
+++ b/src/android/camera_stream.cpp
@@ -119,7 +119,7 @@  int CameraStream::configure()
 
 	if (type_ == Type::Internal) {
 		allocator_ = std::make_unique<FrameBufferAllocator>(cameraDevice_->camera());
-		mutex_ = std::make_unique<std::mutex>();
+		mutex_ = std::make_unique<Mutex>();
 
 		int ret = allocator_->allocate(stream());
 		if (ret < 0)
@@ -208,7 +208,7 @@  FrameBuffer *CameraStream::getBuffer()
 	if (!allocator_)
 		return nullptr;
 
-	std::lock_guard<std::mutex> locker(*mutex_);
+	MutexLocker locker(*mutex_);
 
 	if (buffers_.empty()) {
 		LOG(HAL, Error) << "Buffer underrun";
@@ -226,7 +226,7 @@  void CameraStream::putBuffer(FrameBuffer *buffer)
 	if (!allocator_)
 		return;
 
-	std::lock_guard<std::mutex> locker(*mutex_);
+	MutexLocker locker(*mutex_);
 
 	buffers_.push_back(buffer);
 }
@@ -239,7 +239,7 @@  CameraStream::PostProcessorWorker::PostProcessorWorker(PostProcessor *postProces
 CameraStream::PostProcessorWorker::~PostProcessorWorker()
 {
 	{
-		libcamera::MutexLocker lock(mutex_);
+		MutexLocker lock(mutex_);
 		state_ = State::Stopped;
 	}
 
@@ -250,7 +250,7 @@  CameraStream::PostProcessorWorker::~PostProcessorWorker()
 void CameraStream::PostProcessorWorker::start()
 {
 	{
-		libcamera::MutexLocker lock(mutex_);
+		MutexLocker lock(mutex_);
 		ASSERT(state_ != State::Running);
 		state_ = State::Running;
 	}
@@ -308,7 +308,7 @@  void CameraStream::PostProcessorWorker::run()
 
 void CameraStream::PostProcessorWorker::flush()
 {
-	libcamera::MutexLocker lock(mutex_);
+	MutexLocker lock(mutex_);
 	state_ = State::Flushing;
 	lock.unlock();
 
diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h
index e4808369..c127a0e4 100644
--- a/src/android/camera_stream.h
+++ b/src/android/camera_stream.h
@@ -173,7 +173,7 @@  private:
 	 * The class has to be MoveConstructible as instances are stored in
 	 * an std::vector in CameraDevice.
 	 */
-	std::unique_ptr<std::mutex> mutex_;
+	std::unique_ptr<libcamera::Mutex> mutex_;
 	std::unique_ptr<PostProcessor> postProcessor_;
 
 	std::unique_ptr<PostProcessorWorker> worker_;