Commit 612b0583 authored by François Doray's avatar François Doray Committed by Commit Bot

Revert "[PartitionAlloc] Implement SpinningMutex on macOS."

This reverts commit a777fd4b.

Reason for revert: Suspect for crbug.com/1151948

Original change's description:
> [PartitionAlloc] Implement SpinningMutex on macOS.
>
> macOS has futex()-like locks in pthread, meaning that SpinningFutex can
> be useful there, the same way it is on Windows. Use pthread to implement
> it.
>
> Bug: 998048
> Change-Id: I77df835baf2f099eedcfcee675f7a56ed6b3bb2b
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2550797
> Reviewed-by: Kentaro Hara <haraken@chromium.org>
> Commit-Queue: Benoit L <lizeb@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#830175}

TBR=haraken@chromium.org,lizeb@chromium.org

Change-Id: I636660d7834a80595578ee18ad80b7dfe42d6ed6
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 998048, 1151948
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2555177Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Commit-Queue: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830206}
parent 47a991ea
...@@ -70,19 +70,12 @@ void SpinningMutex::LockSlow() { ...@@ -70,19 +70,12 @@ void SpinningMutex::LockSlow() {
} }
} }
#elif defined(OS_WIN) #else
void SpinningMutex::LockSlow() { void SpinningMutex::LockSlow() {
::AcquireSRWLockExclusive(reinterpret_cast<PSRWLOCK>(&lock_)); ::AcquireSRWLockExclusive(reinterpret_cast<PSRWLOCK>(&lock_));
} }
#elif defined(OS_APPLE)
void SpinningMutex::LockSlow() {
int retval = pthread_mutex_lock(&lock_);
PA_DCHECK(retval == 0);
}
#endif #endif
} // namespace internal } // namespace internal
} // namespace base } // namespace base
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <algorithm> #include <algorithm>
#include <atomic> #include <atomic>
#include "base/allocator/partition_allocator/partition_alloc_check.h"
#include "base/allocator/partition_allocator/yield_processor.h" #include "base/allocator/partition_allocator/yield_processor.h"
#include "base/base_export.h" #include "base/base_export.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
...@@ -19,20 +18,11 @@ ...@@ -19,20 +18,11 @@
#include <windows.h> #include <windows.h>
#endif #endif
#if defined(OS_APPLE)
#include <errno.h>
#include <pthread.h>
#endif
#if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID) #if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID)
#define PA_HAS_LINUX_KERNEL #define PA_HAS_LINUX_KERNEL
#endif #endif
// Linux: futex() makes Try() fast without a syscall. #if defined(PA_HAS_LINUX_KERNEL) || defined(OS_WIN)
// Windows: SRWLock are futex()-like.
// Apple: pthread has futex()-like locks (see pthread_mutex.c in Apple's
// libpthread).
#if defined(PA_HAS_LINUX_KERNEL) || defined(OS_WIN) || defined(OS_APPLE)
#define PA_HAS_SPINNING_MUTEX #define PA_HAS_SPINNING_MUTEX
#endif #endif
...@@ -85,10 +75,8 @@ class LOCKABLE BASE_EXPORT SpinningMutex { ...@@ -85,10 +75,8 @@ class LOCKABLE BASE_EXPORT SpinningMutex {
static constexpr int kLockedContended = 2; static constexpr int kLockedContended = 2;
std::atomic<int32_t> state_{kUnlocked}; std::atomic<int32_t> state_{kUnlocked};
#elif defined(OS_WIN) #else
SRWLOCK lock_ = SRWLOCK_INIT; SRWLOCK lock_ = SRWLOCK_INIT;
#elif defined(OS_APPLE)
pthread_mutex_t lock_ = PTHREAD_MUTEX_INITIALIZER;
#endif #endif
}; };
...@@ -153,7 +141,7 @@ ALWAYS_INLINE void SpinningMutex::Release() { ...@@ -153,7 +141,7 @@ ALWAYS_INLINE void SpinningMutex::Release() {
} }
} }
#elif defined(OS_WIN) #else
ALWAYS_INLINE bool SpinningMutex::Try() { ALWAYS_INLINE bool SpinningMutex::Try() {
return !!::TryAcquireSRWLockExclusive(reinterpret_cast<PSRWLOCK>(&lock_)); return !!::TryAcquireSRWLockExclusive(reinterpret_cast<PSRWLOCK>(&lock_));
...@@ -163,19 +151,6 @@ ALWAYS_INLINE void SpinningMutex::Release() { ...@@ -163,19 +151,6 @@ ALWAYS_INLINE void SpinningMutex::Release() {
::ReleaseSRWLockExclusive(reinterpret_cast<PSRWLOCK>(&lock_)); ::ReleaseSRWLockExclusive(reinterpret_cast<PSRWLOCK>(&lock_));
} }
#elif defined(OS_APPLE)
ALWAYS_INLINE bool SpinningMutex::Try() {
int retval = pthread_mutex_trylock(&lock_);
PA_DCHECK(retval == 0 || retval == EBUSY);
return retval == 0;
}
ALWAYS_INLINE void SpinningMutex::Release() {
int retval = pthread_mutex_unlock(&lock_);
PA_DCHECK(retval == 0);
}
#endif #endif
} // namespace internal } // namespace internal
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment