[libcamera-devel,v5,08/12] android: camera_stream: Protect buffers initialization by mutex_
diff mbox series

Message ID 20211201075348.3121186-9-hiroh@chromium.org
State Accepted
Headers show
Series
  • Introduce clang thread safety annotations
Related show

Commit Message

Hirokazu Honda Dec. 1, 2021, 7:53 a.m. UTC
The initialization on buffers_ in CameraStrean::configure() is not
protected by mutex_. It is no problem because configure() is not
invoked simultaneously while other functions are called. This
protects it to keep the thread safety consistency for buffers access.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/android/camera_stream.cpp | 1 +
 1 file changed, 1 insertion(+)

Comments

Umang Jain Dec. 1, 2021, 10:35 a.m. UTC | #1
Hi Hiro,

On 12/1/21 1:23 PM, Hirokazu Honda wrote:
> The initialization on buffers_ in CameraStrean::configure() is not
> protected by mutex_. It is no problem because configure() is not
> invoked simultaneously while other functions are called. This
> protects it to keep the thread safety consistency for buffers access.
>
> 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 | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp
> index 5a62b7cd..2181d094 100644
> --- a/src/android/camera_stream.cpp
> +++ b/src/android/camera_stream.cpp
> @@ -125,6 +125,7 @@ int CameraStream::configure()
>   		if (ret < 0)
>   			return ret;
>   
> +		MutexLocker lock(*mutex_);
>   		/* Save a pointer to the reserved frame buffers */
>   		for (const auto &frameBuffer : allocator_->buffers(stream()))
>   			buffers_.push_back(frameBuffer.get());

Patch
diff mbox series

diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp
index 5a62b7cd..2181d094 100644
--- a/src/android/camera_stream.cpp
+++ b/src/android/camera_stream.cpp
@@ -125,6 +125,7 @@  int CameraStream::configure()
 		if (ret < 0)
 			return ret;
 
+		MutexLocker lock(*mutex_);
 		/* Save a pointer to the reserved frame buffers */
 		for (const auto &frameBuffer : allocator_->buffers(stream()))
 			buffers_.push_back(frameBuffer.get());