Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: mojo/edk/system/thread_annotations.h

Issue 1426343002: EDK: Move mutex.*, cond_var.*, and thread_annotations.h to //mojo/edk/util. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: oops Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Macros for static thread-safety analysis.
6 //
7 // These are from http://clang.llvm.org/docs/ThreadSafetyAnalysis.html (and thus
8 // really derive from google3's thread_annotations.h).
9 //
10 // TODO(vtl): We're still using the old-fashioned, deprecated annotations
11 // ("locks" instead of "capabilities"), since the new ones don't work yet (in
12 // particular, |TRY_ACQUIRE()| doesn't work: b/19264527).
13 // https://github.com/domokit/mojo/issues/314
14
15 #ifndef MOJO_EDK_SYSTEM_THREAD_ANNOTATIONS_H_
16 #define MOJO_EDK_SYSTEM_THREAD_ANNOTATIONS_H_
17
18 // Enable thread-safety attributes only with clang.
19 // The attributes can be safely erased when compiling with other compilers.
20 #if defined(__clang__)
21 #define MOJO_THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
22 #else
23 #define MOJO_THREAD_ANNOTATION_ATTRIBUTE__(x)
24 #endif
25
26 #define MOJO_GUARDED_BY(x) MOJO_THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
27
28 #define MOJO_PT_GUARDED_BY(x) \
29 MOJO_THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x))
30
31 #define MOJO_ACQUIRED_AFTER(...) \
32 MOJO_THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(__VA_ARGS__))
33
34 #define MOJO_ACQUIRED_BEFORE(...) \
35 MOJO_THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(__VA_ARGS__))
36
37 #define MOJO_EXCLUSIVE_LOCKS_REQUIRED(...) \
38 MOJO_THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(__VA_ARGS__))
39
40 #define MOJO_SHARED_LOCKS_REQUIRED(...) \
41 MOJO_THREAD_ANNOTATION_ATTRIBUTE__(shared_locks_required(__VA_ARGS__))
42
43 #define MOJO_LOCKS_EXCLUDED(...) \
44 MOJO_THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__))
45
46 #define MOJO_LOCK_RETURNED(x) \
47 MOJO_THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))
48
49 #define MOJO_LOCKABLE MOJO_THREAD_ANNOTATION_ATTRIBUTE__(lockable)
50
51 #define MOJO_SCOPED_LOCKABLE MOJO_THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
52
53 #define MOJO_EXCLUSIVE_LOCK_FUNCTION(...) \
54 MOJO_THREAD_ANNOTATION_ATTRIBUTE__(exclusive_lock_function(__VA_ARGS__))
55
56 #define MOJO_SHARED_LOCK_FUNCTION(...) \
57 MOJO_THREAD_ANNOTATION_ATTRIBUTE__(shared_lock_function(__VA_ARGS__))
58
59 #define MOJO_ASSERT_EXCLUSIVE_LOCK(...) \
60 MOJO_THREAD_ANNOTATION_ATTRIBUTE__(assert_exclusive_lock(__VA_ARGS__))
61
62 #define MOJO_ASSERT_SHARED_LOCK(...) \
63 MOJO_THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_lock(__VA_ARGS__))
64
65 #define MOJO_EXCLUSIVE_TRYLOCK_FUNCTION(...) \
66 MOJO_THREAD_ANNOTATION_ATTRIBUTE__(exclusive_trylock_function(__VA_ARGS__))
67
68 #define MOJO_SHARED_TRYLOCK_FUNCTION(...) \
69 MOJO_THREAD_ANNOTATION_ATTRIBUTE__(shared_trylock_function(__VA_ARGS__))
70
71 #define MOJO_UNLOCK_FUNCTION(...) \
72 MOJO_THREAD_ANNOTATION_ATTRIBUTE__(unlock_function(__VA_ARGS__))
73
74 #define MOJO_NO_THREAD_SAFETY_ANALYSIS \
75 MOJO_THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis)
76
77 // Use this in the header to annotate a function/method as not being
78 // thread-safe. This is equivalent to |MOJO_NO_THREAD_SAFETY_ANALYSIS|, but
79 // semantically different: it declares that the caller must abide by additional
80 // restrictions. Limitation: Unfortunately, you can't apply this to a method in
81 // an interface (i.e., pure virtual method) and have it applied automatically to
82 // implementations.
83 #define MOJO_NOT_THREAD_SAFE MOJO_NO_THREAD_SAFETY_ANALYSIS
84
85 #endif // MOJO_EDK_SYSTEM_THREAD_ANNOTATIONS_H_
OLDNEW
« no previous file with comments | « mojo/edk/system/test_channel_endpoint_client.cc ('k') | mojo/edk/system/thread_annotations_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698