diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2021-08-29 21:10:57 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2022-01-03 15:31:19 +0200 |
commit | 152adad97a95c15ae9ac2e1889f94a3dc6412165 (patch) | |
tree | c56fd78c394e99984483d3d2845202930beb2009 | |
parent | ec6921d7f7ef70cd7c5ea3d7a20082d66b8aa6e5 (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>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
-rw-r--r-- | include/libcamera/internal/pipeline_handler.h | 4 | ||||
-rw-r--r-- | src/libcamera/pipeline_handler.cpp | 5 |
2 files changed, 8 insertions, 1 deletions
diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index a7331ced..e5b8ffb4 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -14,6 +14,7 @@ #include <sys/types.h> #include <vector> +#include <libcamera/base/mutex.h> #include <libcamera/base/object.h> #include <libcamera/controls.h> @@ -88,7 +89,8 @@ private: const char *name_; - bool lockOwner_; + Mutex lock_; + bool lockOwner_ LIBCAMERA_TSA_GUARDED_BY(lock_); /* *Not* ownership of lock_ */ friend class PipelineHandlerFactory; }; 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 <sys/sysmacros.h> #include <libcamera/base/log.h> +#include <libcamera/base/mutex.h> #include <libcamera/base/utils.h> #include <libcamera/camera.h> @@ -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; |