Flutter Engine
The Flutter Engine
SkThreadAnnotations.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkThreadAnnotations_DEFINED
9#define SkThreadAnnotations_DEFINED
10
11#include "include/private/base/SkFeatures.h" // IWYU pragma: keep
12
13// The bulk of this code is cribbed from:
14// http://clang.llvm.org/docs/ThreadSafetyAnalysis.html
15
16#if defined(__clang__) && (!defined(SWIG))
17#define SK_THREAD_ANNOTATION_ATTRIBUTE(x) __attribute__((x))
18#else
19#define SK_THREAD_ANNOTATION_ATTRIBUTE(x) // no-op
20#endif
21
22#define SK_CAPABILITY(x) \
23 SK_THREAD_ANNOTATION_ATTRIBUTE(capability(x))
24
25#define SK_SCOPED_CAPABILITY \
26 SK_THREAD_ANNOTATION_ATTRIBUTE(scoped_lockable)
27
28#define SK_GUARDED_BY(x) \
29 SK_THREAD_ANNOTATION_ATTRIBUTE(guarded_by(x))
30
31#define SK_PT_GUARDED_BY(x) \
32 SK_THREAD_ANNOTATION_ATTRIBUTE(pt_guarded_by(x))
33
34#define SK_ACQUIRED_BEFORE(...) \
35 SK_THREAD_ANNOTATION_ATTRIBUTE(acquired_before(__VA_ARGS__))
36
37#define SK_ACQUIRED_AFTER(...) \
38 SK_THREAD_ANNOTATION_ATTRIBUTE(acquired_after(__VA_ARGS__))
39
40#define SK_REQUIRES(...) \
41 SK_THREAD_ANNOTATION_ATTRIBUTE(requires_capability(__VA_ARGS__))
42
43#define SK_REQUIRES_SHARED(...) \
44 SK_THREAD_ANNOTATION_ATTRIBUTE(requires_shared_capability(__VA_ARGS__))
45
46#define SK_ACQUIRE(...) \
47 SK_THREAD_ANNOTATION_ATTRIBUTE(acquire_capability(__VA_ARGS__))
48
49#define SK_ACQUIRE_SHARED(...) \
50 SK_THREAD_ANNOTATION_ATTRIBUTE(acquire_shared_capability(__VA_ARGS__))
51
52// Would be SK_RELEASE, but that is already in use as SK_DEBUG vs. SK_RELEASE.
53#define SK_RELEASE_CAPABILITY(...) \
54 SK_THREAD_ANNOTATION_ATTRIBUTE(release_capability(__VA_ARGS__))
55
56// For symmetry with SK_RELEASE_CAPABILITY.
57#define SK_RELEASE_SHARED_CAPABILITY(...) \
58 SK_THREAD_ANNOTATION_ATTRIBUTE(release_shared_capability(__VA_ARGS__))
59
60#define SK_TRY_ACQUIRE(...) \
61 SK_THREAD_ANNOTATION_ATTRIBUTE(try_acquire_capability(__VA_ARGS__))
62
63#define SK_TRY_ACQUIRE_SHARED(...) \
64 SK_THREAD_ANNOTATION_ATTRIBUTE(try_acquire_shared_capability(__VA_ARGS__))
65
66#define SK_EXCLUDES(...) \
67 SK_THREAD_ANNOTATION_ATTRIBUTE(locks_excluded(__VA_ARGS__))
68
69#define SK_ASSERT_CAPABILITY(x) \
70 SK_THREAD_ANNOTATION_ATTRIBUTE(assert_capability(x))
71
72#define SK_ASSERT_SHARED_CAPABILITY(x) \
73 SK_THREAD_ANNOTATION_ATTRIBUTE(assert_shared_capability(x))
74
75#define SK_RETURN_CAPABILITY(x) \
76 SK_THREAD_ANNOTATION_ATTRIBUTE(lock_returned(x))
77
78#define SK_NO_THREAD_SAFETY_ANALYSIS \
79 SK_THREAD_ANNOTATION_ATTRIBUTE(no_thread_safety_analysis)
80
81#if defined(SK_BUILD_FOR_GOOGLE3) && !defined(SK_BUILD_FOR_WASM_IN_GOOGLE3) \
82 && !defined(SK_BUILD_FOR_WIN)
83 extern "C" {
84 void __google_cxa_guard_acquire_begin(void) __attribute__((weak));
85 void __google_cxa_guard_acquire_end (void) __attribute__((weak));
86 }
87 static inline void sk_potentially_blocking_region_begin() {
88 if (&__google_cxa_guard_acquire_begin) {
89 __google_cxa_guard_acquire_begin();
90 }
91 }
92 static inline void sk_potentially_blocking_region_end() {
93 if (&__google_cxa_guard_acquire_end) {
94 __google_cxa_guard_acquire_end();
95 }
96 }
97 #define SK_POTENTIALLY_BLOCKING_REGION_BEGIN sk_potentially_blocking_region_begin()
98 #define SK_POTENTIALLY_BLOCKING_REGION_END sk_potentially_blocking_region_end()
99#else
100 #define SK_POTENTIALLY_BLOCKING_REGION_BEGIN
101 #define SK_POTENTIALLY_BLOCKING_REGION_END
102#endif
103
104#endif // SkThreadAnnotations_DEFINED
__attribute__((visibility("default"))) int RunBenchmarks(int argc