1 //===-- thread_annotations.h ------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef SCUDO_THREAD_ANNOTATIONS_
10 #define SCUDO_THREAD_ANNOTATIONS_
12 // Enable thread safety attributes only with clang.
13 // The attributes can be safely ignored when compiling with other compilers.
14 #if defined(__clang__)
15 #define THREAD_ANNOTATION_ATTRIBUTE_(x) __attribute__((x))
17 #define THREAD_ANNOTATION_ATTRIBUTE_(x) // no-op
20 #define CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE_(capability(x))
22 #define SCOPED_CAPABILITY THREAD_ANNOTATION_ATTRIBUTE_(scoped_lockable)
24 #define GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE_(guarded_by(x))
26 #define PT_GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE_(pt_guarded_by(x))
28 #define ACQUIRED_BEFORE(...) \
29 THREAD_ANNOTATION_ATTRIBUTE_(acquired_before(__VA_ARGS__))
31 #define ACQUIRED_AFTER(...) \
32 THREAD_ANNOTATION_ATTRIBUTE_(acquired_after(__VA_ARGS__))
34 #define REQUIRES(...) \
35 THREAD_ANNOTATION_ATTRIBUTE_(requires_capability(__VA_ARGS__))
37 #define REQUIRES_SHARED(...) \
38 THREAD_ANNOTATION_ATTRIBUTE_(requires_shared_capability(__VA_ARGS__))
40 #define ACQUIRE(...) \
41 THREAD_ANNOTATION_ATTRIBUTE_(acquire_capability(__VA_ARGS__))
43 #define ACQUIRE_SHARED(...) \
44 THREAD_ANNOTATION_ATTRIBUTE_(acquire_shared_capability(__VA_ARGS__))
46 #define RELEASE(...) \
47 THREAD_ANNOTATION_ATTRIBUTE_(release_capability(__VA_ARGS__))
49 #define RELEASE_SHARED(...) \
50 THREAD_ANNOTATION_ATTRIBUTE_(release_shared_capability(__VA_ARGS__))
52 #define TRY_ACQUIRE(...) \
53 THREAD_ANNOTATION_ATTRIBUTE_(try_acquire_capability(__VA_ARGS__))
55 #define TRY_ACQUIRE_SHARED(...) \
56 THREAD_ANNOTATION_ATTRIBUTE_(try_acquire_shared_capability(__VA_ARGS__))
58 #define EXCLUDES(...) THREAD_ANNOTATION_ATTRIBUTE_(locks_excluded(__VA_ARGS__))
60 #define ASSERT_CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE_(assert_capability(x))
62 #define ASSERT_SHARED_CAPABILITY(x) \
63 THREAD_ANNOTATION_ATTRIBUTE_(assert_shared_capability(x))
65 #define RETURN_CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE_(lock_returned(x))
67 #define NO_THREAD_SAFETY_ANALYSIS \
68 THREAD_ANNOTATION_ATTRIBUTE_(no_thread_safety_analysis)
70 #endif // SCUDO_THREAD_ANNOTATIONS_