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

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