| OLD | NEW |
| 1 // | 1 // |
| 2 // Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 // Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 // | 3 // |
| 4 // Use of this source code is governed by a BSD-style license | 4 // Use of this source code is governed by a BSD-style license |
| 5 // that can be found in the LICENSE file in the root of the source | 5 // that can be found in the LICENSE file in the root of the source |
| 6 // tree. An additional intellectual property rights grant can be found | 6 // tree. An additional intellectual property rights grant can be found |
| 7 // in the file PATENTS. All contributing project authors may | 7 // in the file PATENTS. All contributing project authors may |
| 8 // be found in the AUTHORS file in the root of the source tree. | 8 // be found in the AUTHORS file in the root of the source tree. |
| 9 // | 9 // |
| 10 // Borrowed from | 10 // Borrowed from |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #define THREAD_ANNOTATION_ATTRIBUTE__(x) // no-op | 25 #define THREAD_ANNOTATION_ATTRIBUTE__(x) // no-op |
| 26 #endif | 26 #endif |
| 27 | 27 |
| 28 // Document if a shared variable/field needs to be protected by a lock. | 28 // Document if a shared variable/field needs to be protected by a lock. |
| 29 // GUARDED_BY allows the user to specify a particular lock that should be | 29 // GUARDED_BY allows the user to specify a particular lock that should be |
| 30 // held when accessing the annotated variable, while GUARDED_VAR only | 30 // held when accessing the annotated variable, while GUARDED_VAR only |
| 31 // indicates a shared variable should be guarded (by any lock). GUARDED_VAR | 31 // indicates a shared variable should be guarded (by any lock). GUARDED_VAR |
| 32 // is primarily used when the client cannot express the name of the lock. | 32 // is primarily used when the client cannot express the name of the lock. |
| 33 #define GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x)) | 33 #define GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x)) |
| 34 #define GUARDED_VAR THREAD_ANNOTATION_ATTRIBUTE__(guarded) | 34 #define GUARDED_VAR THREAD_ANNOTATION_ATTRIBUTE__(guarded) |
| 35 // Document if a variable/field is not shared and should be accessed from | |
| 36 // same thread/task queue. | |
| 37 #define ACCESS_ON(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x)) | |
| 38 | 35 |
| 39 // Document if the memory location pointed to by a pointer should be guarded | 36 // Document if the memory location pointed to by a pointer should be guarded |
| 40 // by a lock when dereferencing the pointer. Similar to GUARDED_VAR, | 37 // by a lock when dereferencing the pointer. Similar to GUARDED_VAR, |
| 41 // PT_GUARDED_VAR is primarily used when the client cannot express the name | 38 // PT_GUARDED_VAR is primarily used when the client cannot express the name |
| 42 // of the lock. Note that a pointer variable to a shared memory location | 39 // of the lock. Note that a pointer variable to a shared memory location |
| 43 // could itself be a shared variable. For example, if a shared global pointer | 40 // could itself be a shared variable. For example, if a shared global pointer |
| 44 // q, which is guarded by mu1, points to a shared memory location that is | 41 // q, which is guarded by mu1, points to a shared memory location that is |
| 45 // guarded by mu2, q should be annotated as follows: | 42 // guarded by mu2, q should be annotated as follows: |
| 46 // int *q GUARDED_BY(mu1) PT_GUARDED_BY(mu2); | 43 // int *q GUARDED_BY(mu1) PT_GUARDED_BY(mu2); |
| 47 #define PT_GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(point_to_guarded_by(x)) | 44 #define PT_GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(point_to_guarded_by(x)) |
| 48 #define PT_GUARDED_VAR THREAD_ANNOTATION_ATTRIBUTE__(point_to_guarded) | 45 #define PT_GUARDED_VAR THREAD_ANNOTATION_ATTRIBUTE__(point_to_guarded) |
| 49 | 46 |
| 50 // Document the acquisition order between locks that can be held | 47 // Document the acquisition order between locks that can be held |
| 51 // simultaneously by a thread. For any two locks that need to be annotated | 48 // simultaneously by a thread. For any two locks that need to be annotated |
| 52 // to establish an acquisition order, only one of them needs the annotation. | 49 // to establish an acquisition order, only one of them needs the annotation. |
| 53 // (i.e. You don't have to annotate both locks with both ACQUIRED_AFTER | 50 // (i.e. You don't have to annotate both locks with both ACQUIRED_AFTER |
| 54 // and ACQUIRED_BEFORE.) | 51 // and ACQUIRED_BEFORE.) |
| 55 #define ACQUIRED_AFTER(x) THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(x)) | 52 #define ACQUIRED_AFTER(x) THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(x)) |
| 56 #define ACQUIRED_BEFORE(x) THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(x)) | 53 #define ACQUIRED_BEFORE(x) THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(x)) |
| 57 | 54 |
| 58 // The following three annotations document the lock requirements for | 55 // The following three annotations document the lock requirements for |
| 59 // functions/methods. | 56 // functions/methods. |
| 60 | 57 |
| 61 // Document if a function expects certain locks to be held before it is called | 58 // Document if a function expects certain locks to be held before it is called |
| 62 #define EXCLUSIVE_LOCKS_REQUIRED(...) \ | 59 #define EXCLUSIVE_LOCKS_REQUIRED(...) \ |
| 63 THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(__VA_ARGS__)) | 60 THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(__VA_ARGS__)) |
| 64 // Document if a function expected to be called from same thread/task queue. | |
| 65 #define RUN_ON(x) THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(x)) | |
| 66 | 61 |
| 67 #define SHARED_LOCKS_REQUIRED(...) \ | 62 #define SHARED_LOCKS_REQUIRED(...) \ |
| 68 THREAD_ANNOTATION_ATTRIBUTE__(shared_locks_required(__VA_ARGS__)) | 63 THREAD_ANNOTATION_ATTRIBUTE__(shared_locks_required(__VA_ARGS__)) |
| 69 | 64 |
| 70 // Document the locks acquired in the body of the function. These locks | 65 // Document the locks acquired in the body of the function. These locks |
| 71 // cannot be held when calling this function (as google3's Mutex locks are | 66 // cannot be held when calling this function (as google3's Mutex locks are |
| 72 // non-reentrant). | 67 // non-reentrant). |
| 73 #define LOCKS_EXCLUDED(x) THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(x)) | 68 #define LOCKS_EXCLUDED(x) THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(x)) |
| 74 | 69 |
| 75 // Document the lock the annotated function returns without acquiring it. | 70 // Document the lock the annotated function returns without acquiring it. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 95 THREAD_ANNOTATION_ATTRIBUTE__(shared_trylock_function(__VA_ARGS__)) | 90 THREAD_ANNOTATION_ATTRIBUTE__(shared_trylock_function(__VA_ARGS__)) |
| 96 | 91 |
| 97 #define UNLOCK_FUNCTION(...) \ | 92 #define UNLOCK_FUNCTION(...) \ |
| 98 THREAD_ANNOTATION_ATTRIBUTE__(unlock_function(__VA_ARGS__)) | 93 THREAD_ANNOTATION_ATTRIBUTE__(unlock_function(__VA_ARGS__)) |
| 99 | 94 |
| 100 // An escape hatch for thread safety analysis to ignore the annotated function. | 95 // An escape hatch for thread safety analysis to ignore the annotated function. |
| 101 #define NO_THREAD_SAFETY_ANALYSIS \ | 96 #define NO_THREAD_SAFETY_ANALYSIS \ |
| 102 THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis) | 97 THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis) |
| 103 | 98 |
| 104 #endif // BASE_THREAD_ANNOTATIONS_H_ | 99 #endif // BASE_THREAD_ANNOTATIONS_H_ |
| OLD | NEW |