Rename thread annotation macros to have RTC prefix for syncrhonization primitives.
other macros (e.g. GUARDED_BY) rename postpone to followup CL since it touches codebase wider BUG=webrtc:8198 Review-Url: https://codereview.webrtc.org/3004393002 Cr-Commit-Position: refs/heads/master@{#19701}
This commit is contained in:
parent
f75daa8cb9
commit
9a2d2dd973
@ -146,8 +146,8 @@ private:
|
||||
|
||||
bool KeyPressed() const;
|
||||
|
||||
void Lock() EXCLUSIVE_LOCK_FUNCTION(_critSect) { _critSect.Enter(); };
|
||||
void UnLock() UNLOCK_FUNCTION(_critSect) { _critSect.Leave(); };
|
||||
void Lock() RTC_EXCLUSIVE_LOCK_FUNCTION(_critSect) { _critSect.Enter(); };
|
||||
void UnLock() RTC_UNLOCK_FUNCTION(_critSect) { _critSect.Leave(); };
|
||||
|
||||
inline int32_t InputSanityCheckAfterUnlockedPeriod() const;
|
||||
inline int32_t OutputSanityCheckAfterUnlockedPeriod() const;
|
||||
|
||||
@ -199,10 +199,10 @@ public:
|
||||
void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) override;
|
||||
|
||||
private:
|
||||
void Lock() EXCLUSIVE_LOCK_FUNCTION(_critSect) {
|
||||
void Lock() RTC_EXCLUSIVE_LOCK_FUNCTION(_critSect) {
|
||||
_critSect.Enter();
|
||||
}
|
||||
void UnLock() UNLOCK_FUNCTION(_critSect) {
|
||||
void UnLock() RTC_UNLOCK_FUNCTION(_critSect) {
|
||||
_critSect.Leave();
|
||||
}
|
||||
void WaitForOperationCompletion(pa_operation* paOperation) const;
|
||||
|
||||
@ -56,7 +56,7 @@ CriticalSection::~CriticalSection() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void CriticalSection::Enter() const EXCLUSIVE_LOCK_FUNCTION() {
|
||||
void CriticalSection::Enter() const {
|
||||
#if defined(WEBRTC_WIN)
|
||||
EnterCriticalSection(&crit_);
|
||||
#elif defined(WEBRTC_POSIX)
|
||||
@ -115,7 +115,7 @@ void CriticalSection::Enter() const EXCLUSIVE_LOCK_FUNCTION() {
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CriticalSection::TryEnter() const EXCLUSIVE_TRYLOCK_FUNCTION(true) {
|
||||
bool CriticalSection::TryEnter() const {
|
||||
#if defined(WEBRTC_WIN)
|
||||
return TryEnterCriticalSection(&crit_) != FALSE;
|
||||
#elif defined(WEBRTC_POSIX)
|
||||
@ -148,7 +148,7 @@ bool CriticalSection::TryEnter() const EXCLUSIVE_TRYLOCK_FUNCTION(true) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void CriticalSection::Leave() const UNLOCK_FUNCTION() {
|
||||
void CriticalSection::Leave() const {
|
||||
RTC_DCHECK(CurrentThreadIsOwner());
|
||||
#if defined(WEBRTC_WIN)
|
||||
LeaveCriticalSection(&crit_);
|
||||
|
||||
@ -52,14 +52,14 @@ namespace rtc {
|
||||
// Locking methods (Enter, TryEnter, Leave)are const to permit protecting
|
||||
// members inside a const context without requiring mutable CriticalSections
|
||||
// everywhere.
|
||||
class LOCKABLE CriticalSection {
|
||||
class RTC_LOCKABLE CriticalSection {
|
||||
public:
|
||||
CriticalSection();
|
||||
~CriticalSection();
|
||||
|
||||
void Enter() const EXCLUSIVE_LOCK_FUNCTION();
|
||||
bool TryEnter() const EXCLUSIVE_TRYLOCK_FUNCTION(true);
|
||||
void Leave() const UNLOCK_FUNCTION();
|
||||
void Enter() const RTC_EXCLUSIVE_LOCK_FUNCTION();
|
||||
bool TryEnter() const RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true);
|
||||
void Leave() const RTC_UNLOCK_FUNCTION();
|
||||
|
||||
private:
|
||||
// Use only for RTC_DCHECKing.
|
||||
@ -91,10 +91,11 @@ class LOCKABLE CriticalSection {
|
||||
};
|
||||
|
||||
// CritScope, for serializing execution through a scope.
|
||||
class SCOPED_LOCKABLE CritScope {
|
||||
class RTC_SCOPED_LOCKABLE CritScope {
|
||||
public:
|
||||
explicit CritScope(const CriticalSection* cs) EXCLUSIVE_LOCK_FUNCTION(cs);
|
||||
~CritScope() UNLOCK_FUNCTION();
|
||||
explicit CritScope(const CriticalSection* cs) RTC_EXCLUSIVE_LOCK_FUNCTION(cs);
|
||||
~CritScope() RTC_UNLOCK_FUNCTION();
|
||||
|
||||
private:
|
||||
const CriticalSection* const cs_;
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(CritScope);
|
||||
@ -127,11 +128,11 @@ class TryCritScope {
|
||||
|
||||
// A POD lock used to protect global variables. Do NOT use for other purposes.
|
||||
// No custom constructor or private data member should be added.
|
||||
class LOCKABLE GlobalLockPod {
|
||||
class RTC_LOCKABLE GlobalLockPod {
|
||||
public:
|
||||
void Lock() EXCLUSIVE_LOCK_FUNCTION();
|
||||
void Lock() RTC_EXCLUSIVE_LOCK_FUNCTION();
|
||||
|
||||
void Unlock() UNLOCK_FUNCTION();
|
||||
void Unlock() RTC_UNLOCK_FUNCTION();
|
||||
|
||||
volatile int lock_acquired;
|
||||
};
|
||||
@ -142,10 +143,12 @@ class GlobalLock : public GlobalLockPod {
|
||||
};
|
||||
|
||||
// GlobalLockScope, for serializing execution through a scope.
|
||||
class SCOPED_LOCKABLE GlobalLockScope {
|
||||
class RTC_SCOPED_LOCKABLE GlobalLockScope {
|
||||
public:
|
||||
explicit GlobalLockScope(GlobalLockPod* lock) EXCLUSIVE_LOCK_FUNCTION(lock);
|
||||
~GlobalLockScope() UNLOCK_FUNCTION();
|
||||
explicit GlobalLockScope(GlobalLockPod* lock)
|
||||
RTC_EXCLUSIVE_LOCK_FUNCTION(lock);
|
||||
~GlobalLockScope() RTC_UNLOCK_FUNCTION();
|
||||
|
||||
private:
|
||||
GlobalLockPod* const lock_;
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(GlobalLockScope);
|
||||
|
||||
@ -113,14 +113,10 @@ class RunnerBase : public MessageHandler {
|
||||
int shared_value_;
|
||||
};
|
||||
|
||||
class LOCKABLE CriticalSectionLock {
|
||||
class RTC_LOCKABLE CriticalSectionLock {
|
||||
public:
|
||||
void Lock() EXCLUSIVE_LOCK_FUNCTION() {
|
||||
cs_.Enter();
|
||||
}
|
||||
void Unlock() UNLOCK_FUNCTION() {
|
||||
cs_.Leave();
|
||||
}
|
||||
void Lock() RTC_EXCLUSIVE_LOCK_FUNCTION() { cs_.Enter(); }
|
||||
void Unlock() RTC_UNLOCK_FUNCTION() { cs_.Leave(); }
|
||||
|
||||
private:
|
||||
CriticalSection cs_;
|
||||
|
||||
@ -23,16 +23,16 @@ namespace {
|
||||
const int kMaxMsgLatency = 150; // 150 ms
|
||||
const int kSlowDispatchLoggingThreshold = 50; // 50 ms
|
||||
|
||||
class SCOPED_LOCKABLE MarkProcessingCritScope {
|
||||
class RTC_SCOPED_LOCKABLE MarkProcessingCritScope {
|
||||
public:
|
||||
MarkProcessingCritScope(const CriticalSection* cs, size_t* processing)
|
||||
EXCLUSIVE_LOCK_FUNCTION(cs)
|
||||
RTC_EXCLUSIVE_LOCK_FUNCTION(cs)
|
||||
: cs_(cs), processing_(processing) {
|
||||
cs_->Enter();
|
||||
*processing_ += 1;
|
||||
}
|
||||
|
||||
~MarkProcessingCritScope() UNLOCK_FUNCTION() {
|
||||
~MarkProcessingCritScope() RTC_UNLOCK_FUNCTION() {
|
||||
*processing_ -= 1;
|
||||
cs_->Leave();
|
||||
}
|
||||
|
||||
@ -23,14 +23,14 @@ class RaceCheckerScope;
|
||||
|
||||
// Best-effort race-checking implementation. This primitive uses no
|
||||
// synchronization at all to be as-fast-as-possible in the non-racy case.
|
||||
class LOCKABLE RaceChecker {
|
||||
class RTC_LOCKABLE RaceChecker {
|
||||
public:
|
||||
friend class internal::RaceCheckerScope;
|
||||
RaceChecker();
|
||||
|
||||
private:
|
||||
bool Acquire() const EXCLUSIVE_LOCK_FUNCTION();
|
||||
void Release() const UNLOCK_FUNCTION();
|
||||
bool Acquire() const RTC_EXCLUSIVE_LOCK_FUNCTION();
|
||||
void Release() const RTC_UNLOCK_FUNCTION();
|
||||
|
||||
// Volatile to prevent code being optimized away in Acquire()/Release().
|
||||
mutable volatile int access_count_ = 0;
|
||||
@ -38,25 +38,25 @@ class LOCKABLE RaceChecker {
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
class SCOPED_LOCKABLE RaceCheckerScope {
|
||||
class RTC_SCOPED_LOCKABLE RaceCheckerScope {
|
||||
public:
|
||||
explicit RaceCheckerScope(const RaceChecker* race_checker)
|
||||
EXCLUSIVE_LOCK_FUNCTION(race_checker);
|
||||
RTC_EXCLUSIVE_LOCK_FUNCTION(race_checker);
|
||||
|
||||
bool RaceDetected() const;
|
||||
~RaceCheckerScope() UNLOCK_FUNCTION();
|
||||
~RaceCheckerScope() RTC_UNLOCK_FUNCTION();
|
||||
|
||||
private:
|
||||
const RaceChecker* const race_checker_;
|
||||
const bool race_check_ok_;
|
||||
};
|
||||
|
||||
class SCOPED_LOCKABLE RaceCheckerScopeDoNothing {
|
||||
class RTC_SCOPED_LOCKABLE RaceCheckerScopeDoNothing {
|
||||
public:
|
||||
explicit RaceCheckerScopeDoNothing(const RaceChecker* race_checker)
|
||||
EXCLUSIVE_LOCK_FUNCTION(race_checker) {}
|
||||
RTC_EXCLUSIVE_LOCK_FUNCTION(race_checker) {}
|
||||
|
||||
~RaceCheckerScopeDoNothing() UNLOCK_FUNCTION() {}
|
||||
~RaceCheckerScopeDoNothing() RTC_UNLOCK_FUNCTION() {}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
// Apart from debug builds, we also enable the sequence checker in
|
||||
// builds with RTC_DCHECK_IS_ON so that trybots and waterfall bots
|
||||
// with this define will get the same level of checking as debug bots.
|
||||
#define ENABLE_SEQUENCED_TASK_CHECKER RTC_DCHECK_IS_ON
|
||||
#define RTC_ENABLE_SEQUENCED_TASK_CHECKER RTC_DCHECK_IS_ON
|
||||
|
||||
#include "webrtc/rtc_base/checks.h"
|
||||
#include "webrtc/rtc_base/constructormagic.h"
|
||||
@ -53,18 +53,19 @@ class SequencedTaskCheckerDoNothing {
|
||||
// }
|
||||
//
|
||||
// In Release mode, CalledOnValidThread will always return true.
|
||||
#if ENABLE_SEQUENCED_TASK_CHECKER
|
||||
class LOCKABLE SequencedTaskChecker : public SequencedTaskCheckerImpl {};
|
||||
#if RTC_ENABLE_SEQUENCED_TASK_CHECKER
|
||||
class RTC_LOCKABLE SequencedTaskChecker : public SequencedTaskCheckerImpl {};
|
||||
#else
|
||||
class LOCKABLE SequencedTaskChecker : public SequencedTaskCheckerDoNothing {};
|
||||
#endif // ENABLE_SEQUENCED_TASK_CHECKER_H_
|
||||
class RTC_LOCKABLE SequencedTaskChecker : public SequencedTaskCheckerDoNothing {
|
||||
};
|
||||
#endif // RTC_ENABLE_SEQUENCED_TASK_CHECKER_H_
|
||||
|
||||
namespace internal {
|
||||
class SCOPED_LOCKABLE SequencedTaskCheckerScope {
|
||||
class RTC_SCOPED_LOCKABLE SequencedTaskCheckerScope {
|
||||
public:
|
||||
explicit SequencedTaskCheckerScope(const SequencedTaskChecker* checker)
|
||||
EXCLUSIVE_LOCK_FUNCTION(checker);
|
||||
~SequencedTaskCheckerScope() UNLOCK_FUNCTION();
|
||||
RTC_EXCLUSIVE_LOCK_FUNCTION(checker);
|
||||
~SequencedTaskCheckerScope() RTC_UNLOCK_FUNCTION();
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
@ -72,7 +73,7 @@ class SCOPED_LOCKABLE SequencedTaskCheckerScope {
|
||||
#define RTC_DCHECK_CALLED_SEQUENTIALLY(x) \
|
||||
rtc::internal::SequencedTaskCheckerScope checker(x)
|
||||
|
||||
#undef ENABLE_SEQUENCED_TASK_CHECKER
|
||||
#undef RTC_ENABLE_SEQUENCED_TASK_CHECKER
|
||||
|
||||
} // namespace rtc
|
||||
#endif // WEBRTC_RTC_BASE_SEQUENCED_TASK_CHECKER_H_
|
||||
|
||||
@ -119,9 +119,9 @@ class SignalThread
|
||||
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Worker);
|
||||
};
|
||||
|
||||
class SCOPED_LOCKABLE EnterExit {
|
||||
class RTC_SCOPED_LOCKABLE EnterExit {
|
||||
public:
|
||||
explicit EnterExit(SignalThread* t) EXCLUSIVE_LOCK_FUNCTION(t->cs_)
|
||||
explicit EnterExit(SignalThread* t) RTC_EXCLUSIVE_LOCK_FUNCTION(t->cs_)
|
||||
: t_(t) {
|
||||
t_->cs_.Enter();
|
||||
// If refcount_ is zero then the object has already been deleted and we
|
||||
@ -129,7 +129,7 @@ class SignalThread
|
||||
RTC_DCHECK_NE(0, t_->refcount_);
|
||||
++t_->refcount_;
|
||||
}
|
||||
~EnterExit() UNLOCK_FUNCTION() {
|
||||
~EnterExit() RTC_UNLOCK_FUNCTION() {
|
||||
bool d = (0 == --t_->refcount_);
|
||||
t_->cs_.Leave();
|
||||
if (d)
|
||||
|
||||
@ -153,7 +153,7 @@ static std::unique_ptr<QueuedTask> NewClosure(const Closure& closure,
|
||||
// TaskQueue itself has been deleted or it may happen synchronously while the
|
||||
// TaskQueue instance is being deleted. This may vary from one OS to the next
|
||||
// so assumptions about lifetimes of pending tasks should not be made.
|
||||
class LOCKABLE TaskQueue {
|
||||
class RTC_LOCKABLE TaskQueue {
|
||||
public:
|
||||
// TaskQueue priority levels. On some platforms these will map to thread
|
||||
// priorities, on others such as Mac and iOS, GCD queue priorities.
|
||||
|
||||
@ -100,7 +100,7 @@ class Runnable {
|
||||
|
||||
// WARNING! SUBCLASSES MUST CALL Stop() IN THEIR DESTRUCTORS! See ~Thread().
|
||||
|
||||
class LOCKABLE Thread : public MessageQueue {
|
||||
class RTC_LOCKABLE Thread : public MessageQueue {
|
||||
public:
|
||||
// DEPRECATED.
|
||||
// The default constructor should not be used because it hides whether or
|
||||
|
||||
@ -20,9 +20,9 @@
|
||||
#define WEBRTC_RTC_BASE_THREAD_ANNOTATIONS_H_
|
||||
|
||||
#if defined(__clang__) && (!defined(SWIG))
|
||||
#define THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
|
||||
#define RTC_THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
|
||||
#else
|
||||
#define THREAD_ANNOTATION_ATTRIBUTE__(x) // no-op
|
||||
#define RTC_THREAD_ANNOTATION_ATTRIBUTE__(x) // no-op
|
||||
#endif
|
||||
|
||||
// Document if a shared variable/field needs to be protected by a lock.
|
||||
@ -31,11 +31,9 @@
|
||||
// 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)
|
||||
#define GUARDED_BY(x) RTC_THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
|
||||
#endif
|
||||
#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,
|
||||
@ -45,12 +43,8 @@
|
||||
// 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
|
||||
#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
|
||||
@ -58,10 +52,10 @@
|
||||
// (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))
|
||||
#define ACQUIRED_AFTER(x) RTC_THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(x))
|
||||
#endif
|
||||
#if !defined(ACQUIRED_BEFORE)
|
||||
#define ACQUIRED_BEFORE(x) THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(x))
|
||||
#define ACQUIRED_BEFORE(x) RTC_THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(x))
|
||||
#endif
|
||||
|
||||
// The following three annotations document the lock requirements for
|
||||
@ -70,12 +64,12 @@
|
||||
// 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__))
|
||||
RTC_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__))
|
||||
RTC_THREAD_ANNOTATION_ATTRIBUTE__(shared_locks_required(__VA_ARGS__))
|
||||
#endif
|
||||
|
||||
// Document the locks acquired in the body of the function. These locks
|
||||
@ -83,54 +77,38 @@
|
||||
// non-reentrant).
|
||||
#if !defined(LOCKS_EXCLUDED)
|
||||
#define LOCKS_EXCLUDED(...) \
|
||||
THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__))
|
||||
RTC_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
|
||||
#define RTC_LOCK_RETURNED(x) RTC_THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))
|
||||
|
||||
// Document if a class/type is a lockable type (such as the Mutex class).
|
||||
#if !defined(LOCKABLE)
|
||||
#define LOCKABLE THREAD_ANNOTATION_ATTRIBUTE__(lockable)
|
||||
#endif
|
||||
#define RTC_LOCKABLE RTC_THREAD_ANNOTATION_ATTRIBUTE__(lockable)
|
||||
|
||||
// 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
|
||||
#define RTC_SCOPED_LOCKABLE RTC_THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
|
||||
|
||||
// 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
|
||||
#define RTC_EXCLUSIVE_LOCK_FUNCTION(...) \
|
||||
RTC_THREAD_ANNOTATION_ATTRIBUTE__(exclusive_lock_function(__VA_ARGS__))
|
||||
|
||||
#if !defined(SHARED_LOCK_FUNCTION)
|
||||
#define SHARED_LOCK_FUNCTION(...) \
|
||||
THREAD_ANNOTATION_ATTRIBUTE__(shared_lock_function(__VA_ARGS__))
|
||||
#endif
|
||||
#define RTC_SHARED_LOCK_FUNCTION(...) \
|
||||
RTC_THREAD_ANNOTATION_ATTRIBUTE__(shared_lock_function(__VA_ARGS__))
|
||||
|
||||
#if !defined(EXCLUSIVE_TRYLOCK_FUNCTION)
|
||||
#define EXCLUSIVE_TRYLOCK_FUNCTION(...) \
|
||||
THREAD_ANNOTATION_ATTRIBUTE__(exclusive_trylock_function(__VA_ARGS__))
|
||||
#endif
|
||||
#define RTC_EXCLUSIVE_TRYLOCK_FUNCTION(...) \
|
||||
RTC_THREAD_ANNOTATION_ATTRIBUTE__(exclusive_trylock_function(__VA_ARGS__))
|
||||
|
||||
#if !defined(SHARED_TRYLOCK_FUNCTION)
|
||||
#define SHARED_TRYLOCK_FUNCTION(...) \
|
||||
THREAD_ANNOTATION_ATTRIBUTE__(shared_trylock_function(__VA_ARGS__))
|
||||
#endif
|
||||
#define RTC_SHARED_TRYLOCK_FUNCTION(...) \
|
||||
RTC_THREAD_ANNOTATION_ATTRIBUTE__(shared_trylock_function(__VA_ARGS__))
|
||||
|
||||
#if !defined(UNLOCK_FUNCTION)
|
||||
#define UNLOCK_FUNCTION(...) \
|
||||
THREAD_ANNOTATION_ATTRIBUTE__(unlock_function(__VA_ARGS__))
|
||||
#endif
|
||||
#define RTC_UNLOCK_FUNCTION(...) \
|
||||
RTC_THREAD_ANNOTATION_ATTRIBUTE__(unlock_function(__VA_ARGS__))
|
||||
|
||||
// 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)
|
||||
RTC_THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis)
|
||||
#endif
|
||||
|
||||
#endif // WEBRTC_RTC_BASE_THREAD_ANNOTATIONS_H_
|
||||
|
||||
@ -13,19 +13,21 @@
|
||||
|
||||
namespace {
|
||||
|
||||
class LOCKABLE Lock {
|
||||
class RTC_LOCKABLE Lock {
|
||||
public:
|
||||
void EnterWrite() const EXCLUSIVE_LOCK_FUNCTION() {}
|
||||
void EnterRead() const SHARED_LOCK_FUNCTION() {}
|
||||
bool TryEnterWrite() const EXCLUSIVE_TRYLOCK_FUNCTION(true) { return true; }
|
||||
bool TryEnterRead() const SHARED_TRYLOCK_FUNCTION(true) { return true; }
|
||||
void Leave() const UNLOCK_FUNCTION() {}
|
||||
void EnterWrite() const RTC_EXCLUSIVE_LOCK_FUNCTION() {}
|
||||
void EnterRead() const RTC_SHARED_LOCK_FUNCTION() {}
|
||||
bool TryEnterWrite() const RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true) {
|
||||
return true;
|
||||
}
|
||||
bool TryEnterRead() const RTC_SHARED_TRYLOCK_FUNCTION(true) { return true; }
|
||||
void Leave() const RTC_UNLOCK_FUNCTION() {}
|
||||
};
|
||||
|
||||
class SCOPED_LOCKABLE ScopeLock {
|
||||
class RTC_SCOPED_LOCKABLE ScopeLock {
|
||||
public:
|
||||
explicit ScopeLock(const Lock& lock) EXCLUSIVE_LOCK_FUNCTION(lock) {}
|
||||
~ScopeLock() UNLOCK_FUNCTION() {}
|
||||
explicit ScopeLock(const Lock& lock) RTC_EXCLUSIVE_LOCK_FUNCTION(lock) {}
|
||||
~ScopeLock() RTC_UNLOCK_FUNCTION() {}
|
||||
};
|
||||
|
||||
class ThreadSafe {
|
||||
@ -121,7 +123,7 @@ class ThreadSafe {
|
||||
protected_by_lock_ = unprotected_;
|
||||
}
|
||||
|
||||
const Lock& GetLock() LOCK_RETURNED(lock_) { return lock_; }
|
||||
const Lock& GetLock() RTC_LOCK_RETURNED(lock_) { return lock_; }
|
||||
|
||||
Lock anylock_ ACQUIRED_BEFORE(lock_);
|
||||
Lock lock_;
|
||||
@ -130,10 +132,10 @@ class ThreadSafe {
|
||||
int unprotected_ = 0;
|
||||
|
||||
int protected_by_lock_ GUARDED_BY(lock_) = 0;
|
||||
int protected_by_anything_ GUARDED_VAR = 0;
|
||||
int protected_by_anything_ RTC_GUARDED_VAR = 0;
|
||||
|
||||
int* pt_protected_by_lock_ PT_GUARDED_BY(pt_lock_);
|
||||
int* pt_protected_by_anything_ PT_GUARDED_VAR;
|
||||
int* pt_protected_by_lock_ RTC_PT_GUARDED_BY(pt_lock_);
|
||||
int* pt_protected_by_anything_ RTC_PT_GUARDED_VAR;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@ -71,22 +71,20 @@ class ThreadCheckerDoNothing {
|
||||
//
|
||||
// In Release mode, CalledOnValidThread will always return true.
|
||||
#if ENABLE_THREAD_CHECKER
|
||||
class LOCKABLE ThreadChecker : public ThreadCheckerImpl {
|
||||
};
|
||||
class RTC_LOCKABLE ThreadChecker : public ThreadCheckerImpl {};
|
||||
#else
|
||||
class LOCKABLE ThreadChecker : public ThreadCheckerDoNothing {
|
||||
};
|
||||
class RTC_LOCKABLE ThreadChecker : public ThreadCheckerDoNothing {};
|
||||
#endif // ENABLE_THREAD_CHECKER
|
||||
|
||||
#undef ENABLE_THREAD_CHECKER
|
||||
|
||||
namespace internal {
|
||||
class SCOPED_LOCKABLE AnnounceOnThread {
|
||||
class RTC_SCOPED_LOCKABLE AnnounceOnThread {
|
||||
public:
|
||||
template<typename ThreadLikeObject>
|
||||
template <typename ThreadLikeObject>
|
||||
explicit AnnounceOnThread(const ThreadLikeObject* thread_like_object)
|
||||
EXCLUSIVE_LOCK_FUNCTION(thread_like_object) {}
|
||||
~AnnounceOnThread() UNLOCK_FUNCTION() {}
|
||||
RTC_EXCLUSIVE_LOCK_FUNCTION(thread_like_object) {}
|
||||
~AnnounceOnThread() RTC_UNLOCK_FUNCTION() {}
|
||||
|
||||
template<typename ThreadLikeObject>
|
||||
static bool IsCurrent(const ThreadLikeObject* thread_like_object) {
|
||||
@ -166,10 +164,10 @@ class SCOPED_LOCKABLE AnnounceOnThread {
|
||||
|
||||
// Document if a variable/field is not shared and should be accessed from
|
||||
// same thread/task queue.
|
||||
#define ACCESS_ON(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
|
||||
#define ACCESS_ON(x) RTC_THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
|
||||
|
||||
// Document if a function expected to be called from same thread/task queue.
|
||||
#define RUN_ON(x) THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(x))
|
||||
#define RUN_ON(x) RTC_THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(x))
|
||||
|
||||
#define RTC_DCHECK_RUN_ON(thread_like_object) \
|
||||
rtc::internal::AnnounceOnThread thread_announcer(thread_like_object); \
|
||||
|
||||
@ -19,45 +19,41 @@
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class LOCKABLE RWLockWrapper {
|
||||
class RTC_LOCKABLE RWLockWrapper {
|
||||
public:
|
||||
static RWLockWrapper* CreateRWLock();
|
||||
virtual ~RWLockWrapper() {}
|
||||
|
||||
virtual void AcquireLockExclusive() EXCLUSIVE_LOCK_FUNCTION() = 0;
|
||||
virtual void ReleaseLockExclusive() UNLOCK_FUNCTION() = 0;
|
||||
virtual void AcquireLockExclusive() RTC_EXCLUSIVE_LOCK_FUNCTION() = 0;
|
||||
virtual void ReleaseLockExclusive() RTC_UNLOCK_FUNCTION() = 0;
|
||||
|
||||
virtual void AcquireLockShared() SHARED_LOCK_FUNCTION() = 0;
|
||||
virtual void ReleaseLockShared() UNLOCK_FUNCTION() = 0;
|
||||
virtual void AcquireLockShared() RTC_SHARED_LOCK_FUNCTION() = 0;
|
||||
virtual void ReleaseLockShared() RTC_UNLOCK_FUNCTION() = 0;
|
||||
};
|
||||
|
||||
// RAII extensions of the RW lock. Prevents Acquire/Release missmatches and
|
||||
// provides more compact locking syntax.
|
||||
class SCOPED_LOCKABLE ReadLockScoped {
|
||||
class RTC_SCOPED_LOCKABLE ReadLockScoped {
|
||||
public:
|
||||
ReadLockScoped(RWLockWrapper& rw_lock) SHARED_LOCK_FUNCTION(rw_lock)
|
||||
ReadLockScoped(RWLockWrapper& rw_lock) RTC_SHARED_LOCK_FUNCTION(rw_lock)
|
||||
: rw_lock_(rw_lock) {
|
||||
rw_lock_.AcquireLockShared();
|
||||
}
|
||||
|
||||
~ReadLockScoped() UNLOCK_FUNCTION() {
|
||||
rw_lock_.ReleaseLockShared();
|
||||
}
|
||||
~ReadLockScoped() RTC_UNLOCK_FUNCTION() { rw_lock_.ReleaseLockShared(); }
|
||||
|
||||
private:
|
||||
RWLockWrapper& rw_lock_;
|
||||
};
|
||||
|
||||
class SCOPED_LOCKABLE WriteLockScoped {
|
||||
class RTC_SCOPED_LOCKABLE WriteLockScoped {
|
||||
public:
|
||||
WriteLockScoped(RWLockWrapper& rw_lock) EXCLUSIVE_LOCK_FUNCTION(rw_lock)
|
||||
WriteLockScoped(RWLockWrapper& rw_lock) RTC_EXCLUSIVE_LOCK_FUNCTION(rw_lock)
|
||||
: rw_lock_(rw_lock) {
|
||||
rw_lock_.AcquireLockExclusive();
|
||||
}
|
||||
|
||||
~WriteLockScoped() UNLOCK_FUNCTION() {
|
||||
rw_lock_.ReleaseLockExclusive();
|
||||
}
|
||||
~WriteLockScoped() RTC_UNLOCK_FUNCTION() { rw_lock_.ReleaseLockExclusive(); }
|
||||
|
||||
private:
|
||||
RWLockWrapper& rw_lock_;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user