diff --git a/rtc_base/thread_annotations.h b/rtc_base/thread_annotations.h index de0c5c90da..8569fab16a 100644 --- a/rtc_base/thread_annotations.h +++ b/rtc_base/thread_annotations.h @@ -27,22 +27,16 @@ // Document if a shared variable/field needs to be protected by a lock. // GUARDED_BY allows the user to specify a particular lock that should be -// 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. +// held when accessing the annotated variable. #define RTC_GUARDED_BY(x) RTC_THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x)) -#define RTC_GUARDED_VAR RTC_THREAD_ANNOTATION_ATTRIBUTE__(guarded_var) // Document if the memory location pointed to by a pointer should be guarded -// by a lock when dereferencing the pointer. Similar to GUARDED_VAR, -// PT_GUARDED_VAR is primarily used when the client cannot express the name -// of the lock. Note that a pointer variable to a shared memory location -// could itself be a shared variable. For example, if a shared global pointer -// q, which is guarded by mu1, points to a shared memory location that is -// guarded by mu2, q should be annotated as follows: +// by a lock when dereferencing the pointer. Note that a pointer variable to a +// shared memory location could itself be a shared variable. For example, if a +// shared global pointer 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); #define RTC_PT_GUARDED_BY(x) RTC_THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x)) -#define RTC_PT_GUARDED_VAR RTC_THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_var) // Document the acquisition order between locks that can be held // simultaneously by a thread. For any two locks that need to be annotated diff --git a/rtc_base/thread_annotations_unittest.cc b/rtc_base/thread_annotations_unittest.cc index 2dc2ee7a54..d8a4af1ac3 100644 --- a/rtc_base/thread_annotations_unittest.cc +++ b/rtc_base/thread_annotations_unittest.cc @@ -34,67 +34,50 @@ class ThreadSafe { public: ThreadSafe() { pt_protected_by_lock_ = new int; - pt_protected_by_anything_ = new int; } ~ThreadSafe() { delete pt_protected_by_lock_; - delete pt_protected_by_anything_; } void LockInOrder() { - anylock_.EnterWrite(); + beforelock_.EnterWrite(); lock_.EnterWrite(); pt_lock_.EnterWrite(); pt_lock_.Leave(); lock_.Leave(); - anylock_.Leave(); + beforelock_.Leave(); } - void UnprotectedFunction() RTC_LOCKS_EXCLUDED(anylock_, lock_, pt_lock_) { + void UnprotectedFunction() RTC_LOCKS_EXCLUDED(lock_, pt_lock_) { // Can access unprotected Value. unprotected_ = 15; // Can access pointers themself, but not data they point to. int* tmp = pt_protected_by_lock_; - pt_protected_by_lock_ = pt_protected_by_anything_; - pt_protected_by_anything_ = tmp; + pt_protected_by_lock_ = tmp; } void ReadProtected() { lock_.EnterRead(); - unprotected_ = protected_by_anything_; unprotected_ = protected_by_lock_; lock_.Leave(); if (pt_lock_.TryEnterRead()) { - unprotected_ = *pt_protected_by_anything_; unprotected_ = *pt_protected_by_lock_; pt_lock_.Leave(); } - - anylock_.EnterRead(); - unprotected_ = protected_by_anything_; - unprotected_ = *pt_protected_by_anything_; - anylock_.Leave(); } void WriteProtected() { lock_.EnterWrite(); - protected_by_anything_ = unprotected_; protected_by_lock_ = unprotected_; lock_.Leave(); if (pt_lock_.TryEnterWrite()) { - *pt_protected_by_anything_ = unprotected_; *pt_protected_by_lock_ = unprotected_; pt_lock_.Leave(); } - - anylock_.EnterWrite(); - protected_by_anything_ = unprotected_; - *pt_protected_by_anything_ = unprotected_; - anylock_.Leave(); } void CallReadProtectedFunction() { @@ -125,17 +108,15 @@ class ThreadSafe { const Lock& GetLock() RTC_LOCK_RETURNED(lock_) { return lock_; } - Lock anylock_ RTC_ACQUIRED_BEFORE(lock_); + Lock beforelock_ RTC_ACQUIRED_BEFORE(lock_); Lock lock_; Lock pt_lock_ RTC_ACQUIRED_AFTER(lock_); int unprotected_ = 0; int protected_by_lock_ RTC_GUARDED_BY(lock_) = 0; - int protected_by_anything_ RTC_GUARDED_VAR = 0; int* pt_protected_by_lock_ RTC_PT_GUARDED_BY(pt_lock_); - int* pt_protected_by_anything_ RTC_PT_GUARDED_VAR; }; } // namespace