From 0ed6de4cadecbd977d0fe5545ae3a5d7d4eeccd5 Mon Sep 17 00:00:00 2001 From: Chris Mumford Date: Mon, 14 Aug 2017 14:33:58 -0700 Subject: [PATCH] Check for prior thread annotation macros before defining. The macros in thread_annotations.h (LOCKABLE, SHARED_LOCKS_REQUIRED, etc.) didn't check for an existing definition before defining a new one. This conflicts with other libraries, specifically leveldb: https://github.com/google/leveldb/blob/master/port/thread_annotations.h Change-Id: Ic37b7b63a0fbf84f183e446ee8735ef997b7099d BUG=8096 Change-Id: Ic37b7b63a0fbf84f183e446ee8735ef997b7099d Reviewed-on: https://chromium-review.googlesource.com/614441 Reviewed-by: Peter Thatcher Commit-Queue: Chris Mumford Cr-Commit-Position: refs/heads/master@{#19374} --- webrtc/rtc_base/thread_annotations.h | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/webrtc/rtc_base/thread_annotations.h b/webrtc/rtc_base/thread_annotations.h index 09afb9353f..175b6b6704 100644 --- a/webrtc/rtc_base/thread_annotations.h +++ b/webrtc/rtc_base/thread_annotations.h @@ -30,8 +30,12 @@ // held when accessing the annotated variable, while GUARDED_VAR only // indicates a shared variable should be guarded (by any lock). GUARDED_VAR // is primarily used when the client cannot express the name of the lock. +#if !defined(GUARDED_BY) #define GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x)) +#endif +#if !defined(GUARDED_VAR) #define GUARDED_VAR THREAD_ANNOTATION_ATTRIBUTE__(guarded_var) +#endif // Document if the memory location pointed to by a pointer should be guarded // by a lock when dereferencing the pointer. Similar to GUARDED_VAR, @@ -41,60 +45,92 @@ // q, which is guarded by mu1, points to a shared memory location that is // guarded by mu2, q should be annotated as follows: // int *q GUARDED_BY(mu1) PT_GUARDED_BY(mu2); +#if !defined(PT_GUARDED_BY) #define PT_GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x)) +#endif +#if !defined(PT_GUARDED_VAR) #define PT_GUARDED_VAR THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_var) +#endif // Document the acquisition order between locks that can be held // simultaneously by a thread. For any two locks that need to be annotated // to establish an acquisition order, only one of them needs the annotation. // (i.e. You don't have to annotate both locks with both ACQUIRED_AFTER // and ACQUIRED_BEFORE.) +#if !defined(ACQUIRED_AFTER) #define ACQUIRED_AFTER(x) THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(x)) +#endif +#if !defined(ACQUIRED_BEFORE) #define ACQUIRED_BEFORE(x) THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(x)) +#endif // The following three annotations document the lock requirements for // functions/methods. // Document if a function expects certain locks to be held before it is called +#if !defined(EXCLUSIVE_LOCKS_REQUIRED) #define EXCLUSIVE_LOCKS_REQUIRED(...) \ THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(__VA_ARGS__)) +#endif +#if !defined(SHARED_LOCKS_REQUIRED) #define SHARED_LOCKS_REQUIRED(...) \ THREAD_ANNOTATION_ATTRIBUTE__(shared_locks_required(__VA_ARGS__)) +#endif // Document the locks acquired in the body of the function. These locks // cannot be held when calling this function (as google3's Mutex locks are // non-reentrant). +#if !defined(LOCKS_EXCLUDED) #define LOCKS_EXCLUDED(...) \ THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__)) +#endif // Document the lock the annotated function returns without acquiring it. +#if !defined(LOCK_RETURNED) #define LOCK_RETURNED(x) THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x)) +#endif // Document if a class/type is a lockable type (such as the Mutex class). +#if !defined(LOCKABLE) #define LOCKABLE THREAD_ANNOTATION_ATTRIBUTE__(lockable) +#endif // Document if a class is a scoped lockable type (such as the MutexLock class). +#if !defined(SCOPED_LOCKABLE) #define SCOPED_LOCKABLE THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable) +#endif // The following annotations specify lock and unlock primitives. +#if !defined(EXCLUSIVE_LOCK_FUNCTION) #define EXCLUSIVE_LOCK_FUNCTION(...) \ THREAD_ANNOTATION_ATTRIBUTE__(exclusive_lock_function(__VA_ARGS__)) +#endif +#if !defined(SHARED_LOCK_FUNCTION) #define SHARED_LOCK_FUNCTION(...) \ THREAD_ANNOTATION_ATTRIBUTE__(shared_lock_function(__VA_ARGS__)) +#endif +#if !defined(EXCLUSIVE_TRYLOCK_FUNCTION) #define EXCLUSIVE_TRYLOCK_FUNCTION(...) \ THREAD_ANNOTATION_ATTRIBUTE__(exclusive_trylock_function(__VA_ARGS__)) +#endif +#if !defined(SHARED_TRYLOCK_FUNCTION) #define SHARED_TRYLOCK_FUNCTION(...) \ THREAD_ANNOTATION_ATTRIBUTE__(shared_trylock_function(__VA_ARGS__)) +#endif +#if !defined(UNLOCK_FUNCTION) #define UNLOCK_FUNCTION(...) \ THREAD_ANNOTATION_ATTRIBUTE__(unlock_function(__VA_ARGS__)) +#endif // An escape hatch for thread safety analysis to ignore the annotated function. +#if !defined(NO_THREAD_SAFETY_ANALYSIS) #define NO_THREAD_SAFETY_ANALYSIS \ THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis) +#endif #endif // WEBRTC_RTC_BASE_THREAD_ANNOTATIONS_H_