Gazebo Sim

API Reference

8.7.0
Tsa.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
19 #ifndef THREAD_SAFETY_ANALYSIS_MUTEX_H
20 #define THREAD_SAFETY_ANALYSIS_MUTEX_H
21 
22 // Enable thread safety attributes only with clang.
23 // The attributes can be safely erased when compiling with other compilers.
24 #if defined(__clang__) && (!defined(SWIG))
25 #define THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
26 #else
27 #define THREAD_ANNOTATION_ATTRIBUTE__(x) // no-op
28 #endif
29 
30 #define CAPABILITY(x) \
31  THREAD_ANNOTATION_ATTRIBUTE__(capability(x))
32 
33 #define SCOPED_CAPABILITY \
34  THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
35 
36 #define GUARDED_BY(x) \
37  THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
38 
39 #define PT_GUARDED_BY(x) \
40  THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x))
41 
42 #define ACQUIRED_BEFORE(...) \
43  THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(__VA_ARGS__))
44 
45 #define ACQUIRED_AFTER(...) \
46  THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(__VA_ARGS__))
47 
48 #define REQUIRES(...) \
49  THREAD_ANNOTATION_ATTRIBUTE__(requires_capability(__VA_ARGS__))
50 
51 #define REQUIRES_SHARED(...) \
52  THREAD_ANNOTATION_ATTRIBUTE__(requires_shared_capability(__VA_ARGS__))
53 
54 #define ACQUIRE(...) \
55  THREAD_ANNOTATION_ATTRIBUTE__(acquire_capability(__VA_ARGS__))
56 
57 #define ACQUIRE_SHARED(...) \
58  THREAD_ANNOTATION_ATTRIBUTE__(acquire_shared_capability(__VA_ARGS__))
59 
60 #define RELEASE(...) \
61  THREAD_ANNOTATION_ATTRIBUTE__(release_capability(__VA_ARGS__))
62 
63 #define RELEASE_SHARED(...) \
64  THREAD_ANNOTATION_ATTRIBUTE__(release_shared_capability(__VA_ARGS__))
65 
66 #define RELEASE_GENERIC(...) \
67  THREAD_ANNOTATION_ATTRIBUTE__(release_generic_capability(__VA_ARGS__))
68 
69 #define TRY_ACQUIRE(...) \
70  THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_capability(__VA_ARGS__))
71 
72 #define TRY_ACQUIRE_SHARED(...) \
73  THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_shared_capability(__VA_ARGS__))
74 
75 #define EXCLUDES(...) \
76  THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__))
77 
78 #define ASSERT_CAPABILITY(x) \
79  THREAD_ANNOTATION_ATTRIBUTE__(assert_capability(x))
80 
81 #define ASSERT_SHARED_CAPABILITY(x) \
82  THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_capability(x))
83 
84 #define RETURN_CAPABILITY(x) \
85  THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))
86 
87 #define NO_THREAD_SAFETY_ANALYSIS \
88  THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis)
89 
90 
91 #ifdef USE_LOCK_STYLE_THREAD_SAFETY_ATTRIBUTES
92 // The original version of thread safety analysis the following attribute
93 // definitions. These use a lock-based terminology. They are still in use
94 // by existing thread safety code, and will continue to be supported.
95 
96 // Deprecated.
97 #define PT_GUARDED_VAR \
98  THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_var)
99 
100 // Deprecated.
101 #define GUARDED_VAR \
102  THREAD_ANNOTATION_ATTRIBUTE__(guarded_var)
103 
104 // Replaced by REQUIRES
105 #define EXCLUSIVE_LOCKS_REQUIRED(...) \
106  THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(__VA_ARGS__))
107 
108 // Replaced by REQUIRES_SHARED
109 #define SHARED_LOCKS_REQUIRED(...) \
110  THREAD_ANNOTATION_ATTRIBUTE__(shared_locks_required(__VA_ARGS__))
111 
112 // Replaced by CAPABILITY
113 #define LOCKABLE \
114  THREAD_ANNOTATION_ATTRIBUTE__(lockable)
115 
116 // Replaced by SCOPED_CAPABILITY
117 #define SCOPED_LOCKABLE \
118  THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
119 
120 // Replaced by ACQUIRE
121 #define EXCLUSIVE_LOCK_FUNCTION(...) \
122  THREAD_ANNOTATION_ATTRIBUTE__(exclusive_lock_function(__VA_ARGS__))
123 
124 // Replaced by ACQUIRE_SHARED
125 #define SHARED_LOCK_FUNCTION(...) \
126  THREAD_ANNOTATION_ATTRIBUTE__(shared_lock_function(__VA_ARGS__))
127 
128 // Replaced by RELEASE and RELEASE_SHARED
129 #define UNLOCK_FUNCTION(...) \
130  THREAD_ANNOTATION_ATTRIBUTE__(unlock_function(__VA_ARGS__))
131 
132 // Replaced by TRY_ACQUIRE
133 #define EXCLUSIVE_TRYLOCK_FUNCTION(...) \
134  THREAD_ANNOTATION_ATTRIBUTE__(exclusive_trylock_function(__VA_ARGS__))
135 
136 // Replaced by TRY_ACQUIRE_SHARED
137 #define SHARED_TRYLOCK_FUNCTION(...) \
138  THREAD_ANNOTATION_ATTRIBUTE__(shared_trylock_function(__VA_ARGS__))
139 
140 // Replaced by ASSERT_CAPABILITY
141 #define ASSERT_EXCLUSIVE_LOCK(...) \
142  THREAD_ANNOTATION_ATTRIBUTE__(assert_exclusive_lock(__VA_ARGS__))
143 
144 // Replaced by ASSERT_SHARED_CAPABILITY
145 #define ASSERT_SHARED_LOCK(...) \
146  THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_lock(__VA_ARGS__))
147 
148 // Replaced by EXCLUDE_CAPABILITY.
149 #define LOCKS_EXCLUDED(...) \
150  THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__))
151 
152 // Replaced by RETURN_CAPABILITY
153 #define LOCK_RETURNED(x) \
154  THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))
155 
156 #endif // USE_LOCK_STYLE_THREAD_SAFETY_ATTRIBUTES
157 
158 #endif