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

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

Message

Hirokazu Honda Dec. 1, 2021, 7:07 a.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 v4:
* Address comments from Laurent
* Remove thread_annotations.h include where mutex.h is included
* 05/12: Remove document about members of Mutex classes

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              | 132 ++++++++++++++++++++
 include/libcamera/base/semaphore.h          |   7 +-
 include/libcamera/base/thread.h             |   4 -
 include/libcamera/base/thread_annotations.h |  80 ++++++++++++
 meson.build                                 |   1 +
 src/android/camera_device.cpp               |  10 +-
 src/android/camera_device.h                 |  17 +--
 src/android/camera_hal_manager.h            |  13 +-
 src/android/camera_request.h                |   7 +-
 src/android/camera_stream.cpp               |  15 +--
 src/android/camera_stream.h                 |  15 +--
 src/libcamera/base/meson.build              |   1 +
 src/libcamera/base/mutex.cpp                |  65 ++++++++++
 src/libcamera/base/semaphore.cpp            |   1 -
 src/libcamera/base/signal.cpp               |   2 +-
 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                |   4 +-
 21 files changed, 341 insertions(+), 67 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