47#if (defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))) \
48 || defined(__x86_64__) || defined(__i386__) || defined(__SSE2__)
50 #include <immintrin.h>
51 #define DSPARK_SPIN_PAUSE() _mm_pause()
52#elif defined(_MSC_VER) && defined(_M_ARM64)
55 #define DSPARK_SPIN_PAUSE() __yield()
56#elif defined(__aarch64__) || defined(__arm__) || defined(__ARM_NEON)
58 #define DSPARK_SPIN_PAUSE() __asm__ __volatile__("yield")
61 #define DSPARK_SPIN_PAUSE() ((void)0)
100 if (!flag_.test_and_set(std::memory_order_acquire)) {
105 while (flag_.test(std::memory_order_relaxed)) {
117 return !flag_.test_and_set(std::memory_order_acquire);
133 flag_.clear(std::memory_order_release);
176 : lock_(spinLock), acquired_(spinLock.tryLock()) {}
185 [[nodiscard]]
bool isLocked() const noexcept {
return acquired_; }
198 std::atomic_flag flag_{};
RAII wrapper that acquires the lock on construction and releases on destruction.
~ScopedLock() noexcept
Destructs the guard and releases the lock.
ScopedLock & operator=(const ScopedLock &)=delete
ScopedLock(SpinLock &spinLock) noexcept
Constructs the guard and blocks until the lock is acquired.
ScopedLock(const ScopedLock &)=delete
RAII wrapper that tries to acquire the lock without blocking.
ScopedTryLock & operator=(const ScopedTryLock &)=delete
~ScopedTryLock() noexcept
Destructs the guard and releases the lock ONLY if it was successfully acquired.
ScopedTryLock(const ScopedTryLock &)=delete
bool isLocked() const noexcept
Queries whether the lock acquisition was successful.
ScopedTryLock(SpinLock &spinLock) noexcept
Constructs the guard and attempts a single lock acquisition.
A minimal, real-time safe spin lock with a TTAS wait loop.
bool tryLock() noexcept
Attempts to acquire the lock without waiting.
void unlock() noexcept
Releases the lock, restoring it to the clear state.
SpinLock() noexcept=default
Constructs an unlocked SpinLock.
bool try_lock() noexcept
Standard-library spelling of tryLock().
void lock() noexcept
Acquires the lock, spinning until successful.
Main namespace for the DSPark framework.