Bug 1845715 - Check for failure when getting RegExp match result template r=iain
[gecko.git] / memory / build / Mutex.cpp
blob8e6e0551ead11a272186c1d9649169a4fb6a87d2
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/. */
5 #include "Mutex.h"
7 #include <errno.h>
9 #include "mozilla/Assertions.h"
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.");
25 #endif
28 #if defined(XP_DARWIN)
30 // static
31 bool Mutex::SpinInKernelSpace() {
32 # ifdef __aarch64__
33 return true;
34 # else
35 if (__builtin_available(macOS 10.15, *)) {
36 return true;
39 return false;
40 # endif
43 // static
44 const bool Mutex::gSpinInKernelSpace = SpinInKernelSpace();
46 #endif // defined(XP_DARWIN)