From 152adad97a95c15ae9ac2e1889f94a3dc6412165 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sun, 29 Aug 2021 21:10:57 +0300 Subject: libcamera: pipeline_handler: Make lock() and unlock() thread-safe The PipelineHandler lock() and unlock() functions are documented as thread-safe, but they're not. Fix them using a mutex. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi Reviewed-by: Umang Jain --- src/libcamera/pipeline_handler.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index a9241ac6..03e4b9e6 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -155,6 +156,8 @@ MediaDevice *PipelineHandler::acquireMediaDevice(DeviceEnumerator *enumerator, */ bool PipelineHandler::lock() { + MutexLocker locker(lock_); + /* Do not allow nested locking in the same libcamera instance. */ if (lockOwner_) return false; @@ -183,6 +186,8 @@ bool PipelineHandler::lock() */ void PipelineHandler::unlock() { + MutexLocker locker(lock_); + if (!lockOwner_) return; -- cgit v1.2.1