Debian Codegraph @

memory/build/Mutex.cpp

raw
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 #if defined(XP_WIN)
13 return !!TryEnterCriticalSection(&mMutex);
14 #elif defined(XP_DARWIN)
15 return os_unfair_lock_trylock(&mMutex);
16 #else
17 switch (pthread_mutex_trylock(&mMutex)) {
18 case 0:
19 return true;
20 case EBUSY:
21 return false;
22 default:
23 MOZ_CRASH("pthread_mutex_trylock error.");
24 }
25 #endif
26 }