mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -100,7 +100,7 @@ enum class ConcurrencyRequest {
|
||||
};
|
||||
|
||||
struct ConcurrencyControl {
|
||||
Mutex Lock;
|
||||
ConditionVariable::Mutex Lock;
|
||||
ConditionVariable Queue;
|
||||
|
||||
ConcurrencyControl() = default;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user