2#include <ossia/detail/config.hpp>
4#include <ossia/detail/mutex.hpp>
5#include <ossia/detail/yield.hpp>
15struct TS_CAPABILITY(
"mutex") audio_spin_mutex
17 void lock() noexcept TS_ACQUIRE()
21 constexpr std::array iterations = {5, 10, 3000};
23 for(
int i = 0; i < iterations[0]; ++i)
29 for(
int i = 0; i < iterations[1]; ++i)
39 for(
int i = 0; i < iterations[2]; ++i)
58 std::this_thread::yield();
62 bool try_lock() TS_TRY_ACQUIRE(true)
64 return !locked.load(std::memory_order_relaxed)
65 && !locked.exchange(
true, std::memory_order_acquire);
68 void unlock() TS_RELEASE() { locked.store(
false, std::memory_order_release); }
71 std::atomic<bool> locked{
false};