Lines Matching defs:Mutex

39 // problems when we have multiple versions of Mutex in each shared object.
66 // file.) Basically, because Mutex does non-trivial work in its
74 // it to true (which happens after the Mutex constructor has run.)
147 class Mutex {
149 // Create a Mutex that is not held by anybody. This constructor is
151 // See below for a recommendation for constructing global Mutex
153 inline Mutex();
156 inline ~Mutex();
168 inline void ReaderUnlock(); // Release a read share of this Mutex
184 // Catch the error of writing Mutex when intending MutexLock.
185 Mutex(Mutex* /*ignored*/) {}
187 Mutex(const Mutex&);
188 void operator=(const Mutex&);
191 // Now the implementation of Mutex for various systems
204 Mutex::Mutex() : mutex_(0) { }
205 Mutex::~Mutex() { assert(mutex_ == 0); }
206 void Mutex::Lock() { assert(--mutex_ == -1); }
207 void Mutex::Unlock() { assert(mutex_++ == -1); }
209 bool Mutex::TryLock() { if (mutex_) return false; Lock(); return true; }
211 void Mutex::ReaderLock() { assert(++mutex_ > 0); }
212 void Mutex::ReaderUnlock() { assert(mutex_-- > 0); }
216 Mutex::Mutex() { InitializeCriticalSection(&mutex_); SetIsSafe(); }
217 Mutex::~Mutex() { DeleteCriticalSection(&mutex_); }
218 void Mutex::Lock() { if (is_safe_) EnterCriticalSection(&mutex_); }
219 void Mutex::Unlock() { if (is_safe_) LeaveCriticalSection(&mutex_); }
221 bool Mutex::TryLock() { return is_safe_ ?
224 void Mutex::ReaderLock() { Lock(); } // we don't have read-write locks
225 void Mutex::ReaderUnlock() { Unlock(); }
233 Mutex::Mutex() {
237 Mutex::~Mutex() { CERES_SAFE_PTHREAD(pthread_rwlock_destroy); }
238 void Mutex::Lock() { CERES_SAFE_PTHREAD(pthread_rwlock_wrlock); }
239 void Mutex::Unlock() { CERES_SAFE_PTHREAD(pthread_rwlock_unlock); }
241 bool Mutex::TryLock() { return is_safe_ ?
245 void Mutex::ReaderLock() { CERES_SAFE_PTHREAD(pthread_rwlock_rdlock); }
246 void Mutex::ReaderUnlock() { CERES_SAFE_PTHREAD(pthread_rwlock_unlock); }
255 Mutex::Mutex() {
259 Mutex::~Mutex() { CERES_SAFE_PTHREAD(pthread_mutex_destroy); }
260 void Mutex::Lock() { CERES_SAFE_PTHREAD(pthread_mutex_lock); }
261 void Mutex::Unlock() { CERES_SAFE_PTHREAD(pthread_mutex_unlock); }
263 bool Mutex::TryLock() { return is_safe_ ?
266 void Mutex::ReaderLock() { Lock(); }
267 void Mutex::ReaderUnlock() { Unlock(); }
286 explicit CeresMutexLock(Mutex *mu) : mu_(mu) { mu_->Lock(); }
289 Mutex * const mu_;
298 explicit CeresReaderMutexLock(Mutex *mu) : mu_(mu) { mu_->ReaderLock(); }
301 Mutex * const mu_;
309 explicit CeresWriterMutexLock(Mutex *mu) : mu_(mu) { mu_->WriterLock(); }
312 Mutex * const mu_;