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>
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user