summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-08-29 21:10:57 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-11-19 22:38:44 +0200
commitf6a5d675b1cfd1ee9cb9358526e1f84b821b9e07 (patch)
tree73b0c87750d811008f1a919c74fd342685438dc5 /src
parentd9ae18088a62afc9cebcaa35809fa2457c37bac8 (diff)
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 <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/pipeline_handler.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp
index 3d61311c..2d2bb940 100644
--- a/src/libcamera/pipeline_handler.cpp
+++ b/src/libcamera/pipeline_handler.cpp
@@ -10,6 +10,7 @@
#include <sys/sysmacros.h>
#include <libcamera/base/log.h>
+#include <libcamera/base/thread.h>
#include <libcamera/base/utils.h>
#include <libcamera/camera.h>
@@ -150,6 +151,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;
@@ -178,6 +181,13 @@ bool PipelineHandler::lock()
*/
void PipelineHandler::unlock()
{
+ MutexLocker locker(lock_);
+
+ unlockLocked();
+}
+
+void PipelineHandler::unlockLocked()
+{
if (lockOwner_)
return;