Remove RTC_GUARDED_VAR and RTC_PT_GUARDED_VAR macros
these are deprecated in clang and are noop for other compiles https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#guarded-var-and-pt-guarded-var Bug: None Change-Id: Ie7d32b827933687e4c4a78d27574cbfb7d40d87e Reviewed-on: https://webrtc-review.googlesource.com/17782 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20530}
This commit is contained in:
committed by
Commit Bot
parent
6063e98dcb
commit
37651993ed
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user