[libcamera-devel,v3,00/12] Introduce clang thread safety annotations
mbox series

Message ID 20211130155600.2203123-1-hiroh@chromium.org
Headers show
Series
  • Introduce clang thread safety annotations
Related show

Message

Hirokazu Honda Nov. 30, 2021, 3:55 p.m. UTC
This introduces clang thread safety annotations and applies it
to libcamera Android HAL adaptation layer. It is necessary to add
new classes that wrap std::mutex, std::unique_lock and
std::condition_variable with the annotations. It is because no
C++ standard library annotates all the mutex classes today.
libstdc++ doesn't annotate any classes. libc++ annotates for
std::mutex, std::lock_guard and std::scoped_lock, but doesn't for
std::unique_lock.

Therefore it is possible to use std::mutex if libc++ is used.
Althoug I don't do so In this patch series because the existing
code using std::mutex is not annotated yet.

Document: https://clang.llvm.org/docs/ThreadSafetyAnalysis.html

Change in v3:
* Addresses comments from Laurent
* 05/12: Add documentation about Mutex, MutexLocker and ConditionVariable
* 06/12: Clean up include headers of thread.h and mutex.h

Hirokazu Honda (12):
  libcamera: base: Introduce ConditionVariable
  android: Consolidate mutex classes to Mutex and MutexLocker
  v4l2: Consolidate mutex classes to Mutex and MutexLocker
  libcamera: base: Add thread safety annotation macros
  libcamera: base: Add mutex classes with thread safety annotations
  libcamera: Correct include headers for Mutex classes
  android: camera_hal_manager: Add thread safety annotation
  android: camera_stream: Protect buffers initialization by mutex_
  android: camera_stream: Add thread safety annotation
  android: camera_device: Fix variables access without protection
  android: camera_device: Add thread safety annotation
  android: camera_request: Add thread safety annotation

 include/libcamera/base/meson.build          |   2 +
 include/libcamera/base/mutex.h              | 131 ++++++++++++++++++++
 include/libcamera/base/semaphore.h          |   6 +-
 include/libcamera/base/thread.h             |   4 -
 include/libcamera/base/thread_annotations.h |  80 ++++++++++++
 meson.build                                 |   1 +
 src/android/camera_device.cpp               |   9 +-
 src/android/camera_device.h                 |  18 +--
 src/android/camera_hal_manager.h            |  14 +--
 src/android/camera_request.h                |   8 +-
 src/android/camera_stream.cpp               |  15 +--
 src/android/camera_stream.h                 |  16 +--
 src/libcamera/base/meson.build              |   1 +
 src/libcamera/base/mutex.cpp                | 121 ++++++++++++++++++
 src/libcamera/base/semaphore.cpp            |   1 -
 src/libcamera/base/signal.cpp               |   3 +-
 src/libcamera/base/thread.cpp               |  14 +--
 src/libcamera/camera_manager.cpp            |   4 +-
 src/v4l2/v4l2_camera.h                      |   6 +-
 src/v4l2/v4l2_camera_proxy.cpp              |   8 +-
 src/v4l2/v4l2_camera_proxy.h                |   5 +-
 21 files changed, 399 insertions(+), 68 deletions(-)
 create mode 100644 include/libcamera/base/mutex.h
 create mode 100644 include/libcamera/base/thread_annotations.h
 create mode 100644 src/libcamera/base/mutex.cpp

--
2.34.0.rc2.393.gf8c9666880-goog