Merge pull request #34598 from mikeash/os-unfair-lock-mutex

[Runtime] Use os_unfair_lock for Mutex and StaticMutex on Darwin.
This commit is contained in:
Mike Ash
2020-11-11 11:37:12 -05:00
committed by GitHub
9 changed files with 514 additions and 228 deletions

View File

@@ -100,7 +100,7 @@ enum class ConcurrencyRequest {
};
struct ConcurrencyControl {
Mutex Lock;
ConditionVariable::Mutex Lock;
ConditionVariable Queue;
ConcurrencyControl() = default;

View File

@@ -114,6 +114,29 @@ bool MutexPlatformHelper::try_lock(pthread_mutex_t &mutex) {
/* returnFalseOnEBUSY = */ true);
}
#if HAS_OS_UNFAIR_LOCK
void MutexPlatformHelper::init(os_unfair_lock &lock, bool checked) {
(void)checked; // Unfair locks are always checked.
lock = OS_UNFAIR_LOCK_INIT;
}
void MutexPlatformHelper::destroy(os_unfair_lock &lock) {}
void MutexPlatformHelper::lock(os_unfair_lock &lock) {
os_unfair_lock_lock(&lock);
}
void MutexPlatformHelper::unlock(os_unfair_lock &lock) {
os_unfair_lock_unlock(&lock);
}
bool MutexPlatformHelper::try_lock(os_unfair_lock &lock) {
return os_unfair_lock_trylock(&lock);
}
#endif
void ReadWriteLockPlatformHelper::init(pthread_rwlock_t &rwlock) {
reportError(pthread_rwlock_init(&rwlock, nullptr));
}