libcamera: base: Add mutex classes with thread safety annotations
This replaces Mutex and MutexLocker with our own defined classes. The classes are annotated by clang thread safety annotations. So we can add annotation to code where the classes are used. v4l2 code needs to be annotated, which violates Mutex capability. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
16efd83f5d
commit
c17f172842
7 changed files with 192 additions and 23 deletions
|
@ -11,6 +11,7 @@ libcamera_base_sources = files([
|
|||
'flags.cpp',
|
||||
'log.cpp',
|
||||
'message.cpp',
|
||||
'mutex.cpp',
|
||||
'object.cpp',
|
||||
'semaphore.cpp',
|
||||
'signal.cpp',
|
||||
|
|
55
src/libcamera/base/mutex.cpp
Normal file
55
src/libcamera/base/mutex.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2021, Google Inc.
|
||||
*
|
||||
* mutex.cpp - Mutex classes with clang thread safety annotation
|
||||
*/
|
||||
|
||||
#include <libcamera/base/mutex.h>
|
||||
|
||||
/**
|
||||
* \file base/mutex.h
|
||||
* \brief Mutex classes with clang thread safety annotation
|
||||
*/
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
/**
|
||||
* \class Mutex
|
||||
* \brief std::mutex wrapper with clang thread safety annotation
|
||||
*
|
||||
* The Mutex class wraps a std::mutex instance to add clang thread safety
|
||||
* annotation support. The class exposes the same interface as std::mutex and
|
||||
* can be used as a transparent replacement. It integrates with the
|
||||
* MutexLocker and ConditionVariable classes.
|
||||
*
|
||||
* See https://en.cppreference.com/w/cpp/thread/mutex for the complete API
|
||||
* documentation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \class MutexLocker
|
||||
* \brief std::unique_lock wrapper with clang thread safety annotation
|
||||
*
|
||||
* The MutexLocker class wraps a std::unique_lock instance to add clang thread
|
||||
* safety annotation support. The class exposes the same interface as
|
||||
* std::unique_lock and can be used as a transparent replacement. It integrates
|
||||
* with the Mutex and ConditionVariable classes.
|
||||
*
|
||||
* See https://en.cppreference.com/w/cpp/thread/unique_lock for the complete API
|
||||
* documentation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \class ConditionVariable
|
||||
* \brief std::condition_variable wrapper integrating with MutexLocker
|
||||
*
|
||||
* The ConditionVariable class wraps a std::condition_variable instance to
|
||||
* integrate with the MutexLocker class. The class exposes the same interface as
|
||||
* std::condition_variable and can be used as a transparent replacement.
|
||||
*
|
||||
* See https://en.cppreference.com/w/cpp/thread/condition_variable for the
|
||||
* complete API documentation.
|
||||
*/
|
||||
|
||||
} /* namespace libcamera */
|
|
@ -204,21 +204,6 @@ ThreadData *ThreadData::current()
|
|||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* \typedef ConditionVariable
|
||||
* \brief An alias for std::condition_variable
|
||||
*/
|
||||
|
||||
/**
|
||||
* \typedef Mutex
|
||||
* \brief An alias for std::mutex
|
||||
*/
|
||||
|
||||
/**
|
||||
* \typedef MutexLocker
|
||||
* \brief An alias for std::unique_lock<std::mutex>
|
||||
*/
|
||||
|
||||
/**
|
||||
* \class Thread
|
||||
* \brief A thread of execution
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/thread.h>
|
||||
#include <libcamera/base/mutex.h>
|
||||
|
||||
#include <libcamera/camera.h>
|
||||
|
||||
|
@ -59,7 +59,7 @@ private:
|
|||
int vidioc_querybuf(V4L2CameraFile *file, struct v4l2_buffer *arg);
|
||||
int vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg);
|
||||
int vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg,
|
||||
libcamera::Mutex *lock);
|
||||
libcamera::Mutex *lock) LIBCAMERA_TSA_REQUIRES(*lock);
|
||||
int vidioc_streamon(V4L2CameraFile *file, int *arg);
|
||||
int vidioc_streamoff(V4L2CameraFile *file, int *arg);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue