[libcamera-devel] [PATCH] libcamera: camera_manager: Protect cameras_ by mutex in cleanup()

Laurent Pinchart laurent.pinchart at ideasonboard.com
Mon Jun 20 10:27:56 CEST 2022


Hi Umang,

Thank you for the patch.

On Mon, Jun 20, 2022 at 11:28:09AM +0530, Umang Jain via libcamera-devel wrote:
> From: Hirokazu Honda <hiroh at chromium.org>
> 
> CameraManager::Private::cleanup() accesses cameras_ without acquiring
> mutex_. Fix it.

Could you explain here why the lock is needed ?

> Signed-off-by: Hirokazu Honda <hiroh at chromium.org>
> Signed-off-by: Umang Jain <umang.jain at ideasonboard.com>
> ---
>  src/libcamera/camera_manager.cpp | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp
> index 70d73822..4492edc3 100644
> --- a/src/libcamera/camera_manager.cpp
> +++ b/src/libcamera/camera_manager.cpp
> @@ -178,7 +178,10 @@ void CameraManager::Private::cleanup()
>  	 * process deletion requests from the thread's message queue as the event
>  	 * loop is not in action here.
>  	 */
> +	mutex_.lock();
>  	cameras_.clear();
> +	mutex_.unlock();
> +
>  	dispatchMessages(Message::Type::DeferredDelete);
>  
>  	enumerator_.reset(nullptr);

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list