2
0
Fork 0

Use `os_unfair_lock` on Apple platforms

master
Stuart Carnie 2024-01-20 14:44:46 +07:00
parent c8c483cf57
commit e28b31ec96
No known key found for this signature in database
GPG Key ID: 848D9C9718D78B4F
1 changed files with 21 additions and 0 deletions

@ -33,6 +33,25 @@
#include "core/typedefs.h" #include "core/typedefs.h"
#if defined(__APPLE__)
#include <os/lock.h>
class SpinLock {
mutable os_unfair_lock _lock = OS_UNFAIR_LOCK_INIT;
public:
_ALWAYS_INLINE_ void lock() const {
os_unfair_lock_lock(&_lock);
}
_ALWAYS_INLINE_ void unlock() const {
os_unfair_lock_unlock(&_lock);
}
};
#else
#include <atomic> #include <atomic>
class SpinLock { class SpinLock {
@ -49,4 +68,6 @@ public:
} }
}; };
#endif // __APPLE__
#endif // SPIN_LOCK_H #endif // SPIN_LOCK_H