diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libcamera/media_device.cpp | 14 | ||||
-rw-r--r-- | src/libcamera/pipeline_handler.cpp | 13 |
2 files changed, 13 insertions, 14 deletions
diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index 0b794018..941f86c2 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -63,8 +63,7 @@ LOG_DEFINE_CATEGORY(MediaDevice) * populate() before the media graph can be queried. */ MediaDevice::MediaDevice(const std::string &deviceNode) - : deviceNode_(deviceNode), valid_(false), acquired_(false), - lockOwner_(false) + : deviceNode_(deviceNode), valid_(false), acquired_(false) { } @@ -145,15 +144,9 @@ bool MediaDevice::lock() if (!fd_.isValid()) return false; - /* Do not allow nested locking in the same libcamera instance. */ - if (lockOwner_) - return false; - if (lockf(fd_.get(), F_TLOCK, 0)) return false; - lockOwner_ = true; - return true; } @@ -171,11 +164,6 @@ void MediaDevice::unlock() if (!fd_.isValid()) return; - if (!lockOwner_) - return; - - lockOwner_ = false; - lockf(fd_.get(), F_ULOCK, 0); } diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 0bc0e341..a9241ac6 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -67,7 +67,7 @@ LOG_DEFINE_CATEGORY(Pipeline) * respective factories. */ PipelineHandler::PipelineHandler(CameraManager *manager) - : manager_(manager) + : manager_(manager), lockOwner_(false) { } @@ -155,6 +155,10 @@ MediaDevice *PipelineHandler::acquireMediaDevice(DeviceEnumerator *enumerator, */ bool PipelineHandler::lock() { + /* Do not allow nested locking in the same libcamera instance. */ + if (lockOwner_) + return false; + for (std::shared_ptr<MediaDevice> &media : mediaDevices_) { if (!media->lock()) { unlock(); @@ -162,6 +166,8 @@ bool PipelineHandler::lock() } } + lockOwner_ = true; + return true; } @@ -177,8 +183,13 @@ bool PipelineHandler::lock() */ void PipelineHandler::unlock() { + if (!lockOwner_) + return; + for (std::shared_ptr<MediaDevice> &media : mediaDevices_) media->unlock(); + + lockOwner_ = false; } /** |