• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
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 #ifndef ANDROID_BASE_THREAD_ANNOTATIONS_H
18 #define ANDROID_BASE_THREAD_ANNOTATIONS_H
19 
20 #if defined(__SUPPORT_TS_ANNOTATION__) || defined(__clang__)
21 #define THREAD_ANNOTATION_ATTRIBUTE__(x)   __attribute__((x))
22 #else
23 #define THREAD_ANNOTATION_ATTRIBUTE__(x)   // no-op
24 #endif
25 
26 #define CAPABILITY(x) \
27       THREAD_ANNOTATION_ATTRIBUTE__(capability(x))
28 
29 #define SCOPED_CAPABILITY \
30       THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
31 
32 #define GUARDED_BY(x) \
33       THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
34 
35 #define PT_GUARDED_BY(x) \
36       THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x))
37 
38 #define ACQUIRED_BEFORE(...) \
39       THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(__VA_ARGS__))
40 
41 #define ACQUIRED_AFTER(...) \
42       THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(__VA_ARGS__))
43 
44 #define REQUIRES(...) \
45       THREAD_ANNOTATION_ATTRIBUTE__(requires_capability(__VA_ARGS__))
46 
47 #define REQUIRES_SHARED(...) \
48       THREAD_ANNOTATION_ATTRIBUTE__(requires_shared_capability(__VA_ARGS__))
49 
50 #define ACQUIRE(...) \
51       THREAD_ANNOTATION_ATTRIBUTE__(acquire_capability(__VA_ARGS__))
52 
53 #define ACQUIRE_SHARED(...) \
54       THREAD_ANNOTATION_ATTRIBUTE__(acquire_shared_capability(__VA_ARGS__))
55 
56 #define RELEASE(...) \
57       THREAD_ANNOTATION_ATTRIBUTE__(release_capability(__VA_ARGS__))
58 
59 #define RELEASE_SHARED(...) \
60       THREAD_ANNOTATION_ATTRIBUTE__(release_shared_capability(__VA_ARGS__))
61 
62 #define TRY_ACQUIRE(...) \
63       THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_capability(__VA_ARGS__))
64 
65 #define TRY_ACQUIRE_SHARED(...) \
66       THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_shared_capability(__VA_ARGS__))
67 
68 #define EXCLUDES(...) \
69       THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__))
70 
71 #define ASSERT_CAPABILITY(x) \
72       THREAD_ANNOTATION_ATTRIBUTE__(assert_capability(x))
73 
74 #define ASSERT_SHARED_CAPABILITY(x) \
75       THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_capability(x))
76 
77 #define RETURN_CAPABILITY(x) \
78       THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))
79 
80 #define NO_THREAD_SAFETY_ANALYSIS \
81       THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis)
82 
83 #endif  // ANDROID_BASE_THREAD_ANNOTATIONS_H
84