/** * Tries to lock the Mutex */ bool TryLock() { if (!mutex.try_lock()) { #ifndef NDEBUG assert(!IsLockedByCurrent()); #endif return false; } #ifndef NDEBUG debug_mutex.lock(); assert(!locked); locked = true; owner = ThreadHandle::GetCurrent(); debug_mutex.unlock(); #endif return true; };
/** * Locks the Mutex */ void Lock() { #ifdef NDEBUG mutex.lock(); #else if (!mutex.try_lock()) { /* locking has failed - at this point, "locked" and "owner" are either not yet update, or "owner" is set to another thread */ assert(!IsLockedByCurrent()); mutex.lock(); } /* we have just obtained the mutex; the "locked" flag must not be set */ debug_mutex.lock(); assert(!locked); locked = true; owner = ThreadHandle::GetCurrent(); debug_mutex.unlock(); #endif };