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 SHARED_CAPABILITY(...) \ 33 THREAD_ANNOTATION_ATTRIBUTE__(shared_capability(__VA_ARGS__)) 34 35 #define GUARDED_BY(x) \ 36 THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x)) 37 38 #define PT_GUARDED_BY(x) \ 39 THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x)) 40 41 #define ACQUIRED_BEFORE(...) \ 42 THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(__VA_ARGS__)) 43 44 #define ACQUIRED_AFTER(...) \ 45 THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(__VA_ARGS__)) 46 47 #define REQUIRES(...) \ 48 THREAD_ANNOTATION_ATTRIBUTE__(requires_capability(__VA_ARGS__)) 49 50 #define REQUIRES_SHARED(...) \ 51 THREAD_ANNOTATION_ATTRIBUTE__(requires_shared_capability(__VA_ARGS__)) 52 53 #define ACQUIRE(...) \ 54 THREAD_ANNOTATION_ATTRIBUTE__(acquire_capability(__VA_ARGS__)) 55 56 #define ACQUIRE_SHARED(...) \ 57 THREAD_ANNOTATION_ATTRIBUTE__(acquire_shared_capability(__VA_ARGS__)) 58 59 #define RELEASE(...) \ 60 THREAD_ANNOTATION_ATTRIBUTE__(release_capability(__VA_ARGS__)) 61 62 #define RELEASE_SHARED(...) \ 63 THREAD_ANNOTATION_ATTRIBUTE__(release_shared_capability(__VA_ARGS__)) 64 65 #define TRY_ACQUIRE(...) \ 66 THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_capability(__VA_ARGS__)) 67 68 #define TRY_ACQUIRE_SHARED(...) \ 69 THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_shared_capability(__VA_ARGS__)) 70 71 #define EXCLUDES(...) \ 72 THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__)) 73 74 #define ASSERT_CAPABILITY(x) \ 75 THREAD_ANNOTATION_ATTRIBUTE__(assert_capability(x)) 76 77 #define ASSERT_SHARED_CAPABILITY(x) \ 78 THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_capability(x)) 79 80 #define RETURN_CAPABILITY(x) \ 81 THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x)) 82 83 #define EXCLUSIVE_LOCK_FUNCTION(...) \ 84 THREAD_ANNOTATION_ATTRIBUTE__(exclusive_lock_function(__VA_ARGS__)) 85 86 #define EXCLUSIVE_TRYLOCK_FUNCTION(...) \ 87 THREAD_ANNOTATION_ATTRIBUTE__(exclusive_trylock_function(__VA_ARGS__)) 88 89 #define SHARED_LOCK_FUNCTION(...) \ 90 THREAD_ANNOTATION_ATTRIBUTE__(shared_lock_function(__VA_ARGS__)) 91 92 #define SHARED_TRYLOCK_FUNCTION(...) \ 93 THREAD_ANNOTATION_ATTRIBUTE__(shared_trylock_function(__VA_ARGS__)) 94 95 #define UNLOCK_FUNCTION(...) \ 96 THREAD_ANNOTATION_ATTRIBUTE__(unlock_function(__VA_ARGS__)) 97 98 #define SCOPED_LOCKABLE \ 99 THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable) 100 101 #define LOCK_RETURNED(x) \ 102 THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x)) 103 104 #define NO_THREAD_SAFETY_ANALYSIS \ 105 THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis) 106 107 #endif // ANDROID_BASE_THREAD_ANNOTATIONS_H 108