Lines Matching refs:Mutex
6 * A simple mutex wrapper, supporting locks and read-write locks.
47 # error Need to implement mutex.h for your architecture, or #define NO_THREADS
50 class Mutex {
52 // Create a Mutex that is not held by anybody.
53 inline Mutex();
56 inline ~Mutex();
66 inline void ReaderUnlock(); // Release a read share of this Mutex
74 // Catch the error of writing Mutex when intending MutexLock.
75 Mutex(Mutex *ignored);
77 Mutex(const Mutex&);
78 void operator=(const Mutex&);
81 // Now the implementation of Mutex for various systems
95 Mutex::Mutex() : mutex_(0) { }
96 Mutex::~Mutex() { assert(mutex_ == 0); }
97 void Mutex::Lock() { assert(--mutex_ == -1); }
98 void Mutex::Unlock() { assert(mutex_++ == -1); }
99 bool Mutex::TryLock() { if (mutex_) return false; Lock(); return true; }
100 void Mutex::ReaderLock() { assert(++mutex_ > 0); }
101 void Mutex::ReaderUnlock() { assert(mutex_-- > 0); }
108 Mutex::Mutex() { SAFE_PTHREAD(pthread_rwlock_init(&mutex_, NULL)); }
109 Mutex::~Mutex() { SAFE_PTHREAD(pthread_rwlock_destroy(&mutex_)); }
110 void Mutex::Lock() { SAFE_PTHREAD(pthread_rwlock_wrlock(&mutex_)); }
111 void Mutex::Unlock() { SAFE_PTHREAD(pthread_rwlock_unlock(&mutex_)); }
112 bool Mutex::TryLock() { return pthread_rwlock_trywrlock(&mutex_) == 0; }
113 void Mutex::ReaderLock() { SAFE_PTHREAD(pthread_rwlock_rdlock(&mutex_)); }
114 void Mutex::ReaderUnlock() { SAFE_PTHREAD(pthread_rwlock_unlock(&mutex_)); }
123 Mutex::Mutex() { SAFE_PTHREAD(pthread_mutex_init(&mutex_, NULL)); }
124 Mutex::~Mutex() { SAFE_PTHREAD(pthread_mutex_destroy(&mutex_)); }
125 void Mutex::Lock() { SAFE_PTHREAD(pthread_mutex_lock(&mutex_)); }
126 void Mutex::Unlock() { SAFE_PTHREAD(pthread_mutex_unlock(&mutex_)); }
127 bool Mutex::TryLock() { return pthread_mutex_trylock(&mutex_) == 0; }
128 void Mutex::ReaderLock() { Lock(); } // we don't have read-write locks
129 void Mutex::ReaderUnlock() { Unlock(); }
134 Mutex::Mutex() { InitializeCriticalSection(&mutex_); }
135 Mutex::~Mutex() { DeleteCriticalSection(&mutex_); }
136 void Mutex::Lock() { EnterCriticalSection(&mutex_); }
137 void Mutex::Unlock() { LeaveCriticalSection(&mutex_); }
138 bool Mutex::TryLock() { return TryEnterCriticalSection(&mutex_) != 0; }
139 void Mutex::ReaderLock() { Lock(); } // we don't have read-write locks
140 void Mutex::ReaderUnlock() { Unlock(); }
151 explicit MutexLock(Mutex *mu) : mu_(mu) { mu_->Lock(); }
154 Mutex * const mu_;
163 explicit ReaderMutexLock(Mutex *mu) : mu_(mu) { mu_->ReaderLock(); }
166 Mutex * const mu_;
174 explicit WriterMutexLock(Mutex *mu) : mu_(mu) { mu_->WriterLock(); }
177 Mutex * const mu_;
188 // Provide safe way to declare and use global, linker-initialized mutex. Sigh.
201 static Mutex name