From f6a5d675b1cfd1ee9cb9358526e1f84b821b9e07 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 --- src/libcamera/pipeline_handler.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') 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 #include +#include #include #include @@ -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; @@ -177,6 +180,13 @@ bool PipelineHandler::lock() * \sa lock() */ void PipelineHandler::unlock() +{ + MutexLocker locker(lock_); + + unlockLocked(); +} + +void PipelineHandler::unlockLocked() { if (lockOwner_) return; -- cgit v1.2.1