tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Mutex.cpp (662B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #include "Mutex.h"
      6 
      7 #include <errno.h>
      8 
      9 #include "mozilla/Assertions.h"
     10 
     11 bool Mutex::TryLock() {
     12  MOZ_ASSERT(mInitialised);
     13 
     14 #if defined(XP_WIN)
     15  return !!TryEnterCriticalSection(mMutex.addr());
     16 #elif defined(XP_DARWIN)
     17  return os_unfair_lock_trylock(&mMutex);
     18 #else
     19  switch (pthread_mutex_trylock(&mMutex)) {
     20    case 0:
     21      return true;
     22    case EBUSY:
     23      return false;
     24    default:
     25      MOZ_CRASH("pthread_mutex_trylock error.");
     26  }
     27 #endif
     28 }