libcamera: include/libcamera/base/thread_annotations.h Source File

libcamera v0.3.2 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
thread_annotations.h
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2021, Google Inc.
4 *
5 * Macro of Clang thread safety analysis
6 */
7
8#pragma once
9
10#include <libcamera/base/private.h>
11
12/*
13 * Enable thread safety attributes only with clang.
14 * The attributes can be safely erased when compiling with other compilers.
15 */
16#if defined(__clang__) && !defined(SWIG)
17#define LIBCAMERA_TSA_ATTRIBUTE__(x) __attribute__((x))
18#else
19#define LIBCAMERA_TSA_ATTRIBUTE__(x) /* no-op */
20#endif
21
22/* See https://clang.llvm.org/docs/ThreadSafetyAnalysis.html for these usages. */
23
24#define LIBCAMERA_TSA_CAPABILITY(x) \
25 LIBCAMERA_TSA_ATTRIBUTE__(capability(x))
26
27#define LIBCAMERA_TSA_SCOPED_CAPABILITY \
28 LIBCAMERA_TSA_ATTRIBUTE__(scoped_lockable)
29
30#define LIBCAMERA_TSA_GUARDED_BY(x) \
31 LIBCAMERA_TSA_ATTRIBUTE__(guarded_by(x))
32
33#define LIBCAMERA_TSA_PT_GUARDED_BY(x) \
34 LIBCAMERA_TSA_ATTRIBUTE__(pt_guarded_by(x))
35
36#define LIBCAMERA_TSA_ACQUIRED_BEFORE(...) \
37 LIBCAMERA_TSA_ATTRIBUTE__(acquired_before(__VA_ARGS__))
38
39#define LIBCAMERA_TSA_ACQUIRED_AFTER(...) \
40 LIBCAMERA_TSA_ATTRIBUTE__(acquired_after(__VA_ARGS__))
41
42#define LIBCAMERA_TSA_REQUIRES(...) \
43 LIBCAMERA_TSA_ATTRIBUTE__(requires_capability(__VA_ARGS__))
44
45#define LIBCAMERA_TSA_REQUIRES_SHARED(...) \
46 LIBCAMERA_TSA_ATTRIBUTE__(requires_shared_capability(__VA_ARGS__))
47
48#define LIBCAMERA_TSA_ACQUIRE(...) \
49 LIBCAMERA_TSA_ATTRIBUTE__(acquire_capability(__VA_ARGS__))
50
51#define LIBCAMERA_TSA_ACQUIRE_SHARED(...) \
52 LIBCAMERA_TSA_ATTRIBUTE__(acquire_shared_capability(__VA_ARGS__))
53
54#define LIBCAMERA_TSA_RELEASE(...) \
55 LIBCAMERA_TSA_ATTRIBUTE__(release_capability(__VA_ARGS__))
56
57#define LIBCAMERA_TSA_RELEASE_SHARED(...) \
58 LIBCAMERA_TSA_ATTRIBUTE__(release_shared_capability(__VA_ARGS__))
59
60#define LIBCAMERA_TSA_RELEASE_GENERIC(...) \
61 LIBCAMERA_TSA_ATTRIBUTE__(release_generic_capability(__VA_ARGS__))
62
63#define LIBCAMERA_TSA_TRY_ACQUIRE(...) \
64 LIBCAMERA_TSA_ATTRIBUTE__(try_acquire_capability(__VA_ARGS__))
65
66#define LIBCAMERA_TSA_TRY_ACQUIRE_SHARED(...) \
67 LIBCAMERA_TSA_ATTRIBUTE__(try_acquire_shared_capability(__VA_ARGS__))
68
69#define LIBCAMERA_TSA_EXCLUDES(...) \
70 LIBCAMERA_TSA_ATTRIBUTE__(locks_excluded(__VA_ARGS__))
71
72#define LIBCAMERA_TSA_ASSERT_CAPABILITY(x) \
73 LIBCAMERA_TSA_ATTRIBUTE__(assert_capability(x))
74
75#define LIBCAMERA_TSA_ASSERT_SHARED_CAPABILITY(x) \
76 LIBCAMERA_TSA_ATTRIBUTE__(assert_shared_capability(x))
77
78#define LIBCAMERA_TSA_RETURN_CAPABILITY(x) \
79 LIBCAMERA_TSA_ATTRIBUTE__(lock_returned(x))
80
81#define LIBCAMERA_TSA_NO_THREAD_SAFETY_ANALYSIS \
82 LIBCAMERA_TSA_ATTRIBUTE__(no_thread_safety_analysis)