diff options
author | Stuart Carnie <stuart.carnie@gmail.com> | 2024-01-20 14:44:46 +1100 |
---|---|---|
committer | Stuart Carnie <stuart.carnie@gmail.com> | 2024-01-21 06:23:09 +1100 |
commit | e28b31ec9665f2ec92cf3e1f72fd43b85e3d980c (patch) | |
tree | 3c628163b47759464466228da51dcbb5944509fd | |
parent | c8c483cf57a768110fce57e509f9b855e69d34b7 (diff) | |
download | redot-engine-e28b31ec9665f2ec92cf3e1f72fd43b85e3d980c.tar.gz |
Use `os_unfair_lock` on Apple platforms
-rw-r--r-- | core/os/spin_lock.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/core/os/spin_lock.h b/core/os/spin_lock.h index 93ea782b60..d386cd5890 100644 --- a/core/os/spin_lock.h +++ b/core/os/spin_lock.h @@ -33,6 +33,25 @@ #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> class SpinLock { @@ -49,4 +68,6 @@ public: } }; +#endif // __APPLE__ + #endif // SPIN_LOCK_H |