#define WEBRTC_BASE_CRITICALSECTION_H__
#include "webrtc/base/constructormagic.h"
+#include "webrtc/base/thread_annotations.h"
#if defined(WEBRTC_WIN)
#include "webrtc/base/win32.h"
namespace rtc {
#if defined(WEBRTC_WIN)
-class CriticalSection {
+class LOCKABLE CriticalSection {
public:
CriticalSection() {
InitializeCriticalSection(&crit_);
~CriticalSection() {
DeleteCriticalSection(&crit_);
}
- void Enter() {
+ void Enter() EXCLUSIVE_LOCK_FUNCTION() {
EnterCriticalSection(&crit_);
TRACK_OWNER(thread_ = GetCurrentThreadId());
}
- bool TryEnter() {
+ bool TryEnter() EXCLUSIVE_TRYLOCK_FUNCTION(true) {
if (TryEnterCriticalSection(&crit_) != FALSE) {
TRACK_OWNER(thread_ = GetCurrentThreadId());
return true;
}
return false;
}
- void Leave() {
+ void Leave() UNLOCK_FUNCTION() {
TRACK_OWNER(thread_ = 0);
LeaveCriticalSection(&crit_);
}
#endif // WEBRTC_WIN
#if defined(WEBRTC_POSIX)
-class CriticalSection {
+class LOCKABLE CriticalSection {
public:
CriticalSection() {
pthread_mutexattr_t mutex_attribute;
~CriticalSection() {
pthread_mutex_destroy(&mutex_);
}
- void Enter() {
+ void Enter() EXCLUSIVE_LOCK_FUNCTION() {
pthread_mutex_lock(&mutex_);
TRACK_OWNER(thread_ = pthread_self());
}
- bool TryEnter() {
+ bool TryEnter() EXCLUSIVE_TRYLOCK_FUNCTION(true) {
if (pthread_mutex_trylock(&mutex_) == 0) {
TRACK_OWNER(thread_ = pthread_self());
return true;
}
return false;
}
- void Leave() {
+ void Leave() UNLOCK_FUNCTION() {
TRACK_OWNER(thread_ = 0);
pthread_mutex_unlock(&mutex_);
}
#endif // WEBRTC_POSIX
// CritScope, for serializing execution through a scope.
-class CritScope {
+class SCOPED_LOCKABLE CritScope {
public:
- explicit CritScope(CriticalSection *pcrit) {
+ explicit CritScope(CriticalSection *pcrit) EXCLUSIVE_LOCK_FUNCTION(pcrit) {
pcrit_ = pcrit;
pcrit_->Enter();
}
- ~CritScope() {
+ ~CritScope() UNLOCK_FUNCTION() {
pcrit_->Leave();
}
private: