1 #pragma once
2 /*
3  * Copyright (C) 2016 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #if defined(__SUPPORT_TS_ANNOTATION__) || defined(__clang__)
19 #define THREAD_ANNOTATION_ATTRIBUTE__(x)   __attribute__((x))
20 #else
21 #define THREAD_ANNOTATION_ATTRIBUTE__(x)   // no-op
22 #endif
23 
24 #define CAPABILITY(x) \
25       THREAD_ANNOTATION_ATTRIBUTE__(capability(x))
26 
27 #define SCOPED_CAPABILITY \
28       THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
29 
30 #define GUARDED_BY(x) \
31       THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
32 
33 #define PT_GUARDED_BY(x) \
34       THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x))
35 
36 #define ACQUIRED_BEFORE(...) \
37       THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(__VA_ARGS__))
38 
39 #define ACQUIRED_AFTER(...) \
40       THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(__VA_ARGS__))
41 
42 #define REQUIRES(...) \
43       THREAD_ANNOTATION_ATTRIBUTE__(requires_capability(__VA_ARGS__))
44 
45 #define REQUIRES_SHARED(...) \
46       THREAD_ANNOTATION_ATTRIBUTE__(requires_shared_capability(__VA_ARGS__))
47 
48 #define ACQUIRE(...) \
49       THREAD_ANNOTATION_ATTRIBUTE__(acquire_capability(__VA_ARGS__))
50 
51 #define ACQUIRE_SHARED(...) \
52       THREAD_ANNOTATION_ATTRIBUTE__(acquire_shared_capability(__VA_ARGS__))
53 
54 #define RELEASE(...) \
55       THREAD_ANNOTATION_ATTRIBUTE__(release_capability(__VA_ARGS__))
56 
57 #define RELEASE_SHARED(...) \
58       THREAD_ANNOTATION_ATTRIBUTE__(release_shared_capability(__VA_ARGS__))
59 
60 #define TRY_ACQUIRE(...) \
61       THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_capability(__VA_ARGS__))
62 
63 #define TRY_ACQUIRE_SHARED(...) \
64       THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_shared_capability(__VA_ARGS__))
65 
66 #define EXCLUDES(...) \
67       THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__))
68 
69 #define ASSERT_CAPABILITY(x) \
70       THREAD_ANNOTATION_ATTRIBUTE__(assert_capability(x))
71 
72 #define ASSERT_SHARED_CAPABILITY(x) \
73       THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_capability(x))
74 
75 #define RETURN_CAPABILITY(x) \
76       THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))
77 
78 #define NO_THREAD_SAFETY_ANALYSIS \
79       THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis)
80