Skip to content

Commit

Permalink
Use os_unfair_lock on Apple platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartcarnie committed Jan 20, 2024
1 parent c8c483c commit e28b31e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions core/os/spin_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -49,4 +68,6 @@ class SpinLock {
}
};

#endif // __APPLE__

#endif // SPIN_LOCK_H

0 comments on commit e28b31e

Please sign in to comment.