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:
parent
ec6921d7f7
commit
152adad97a
2 changed files with 8 additions and 1 deletions
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue