Beispiel #1
0
  /**
   * Tries to lock the Mutex
   */
  bool TryLock() {
    if (!mutex.TryLock()) {
#ifndef NDEBUG
      assert(!IsLockedByCurrent());
#endif
      return false;
    }

#ifndef NDEBUG
    debug_mutex.Lock();
    assert(!locked);
    locked = true;
    owner = ThreadHandle::GetCurrent();
    debug_mutex.Unlock();

    ++thread_locks_held;
#endif
    return true;
  };
Beispiel #2
0
  /**
   * Locks the Mutex
   */
  void Lock() {
#ifdef NDEBUG
    mutex.Lock();
#else
    if (!mutex.TryLock()) {
      /* 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();

    ++thread_locks_held;
#endif
  };