35 _mutex.unlock_shared();
63 bool try_lock_shared(
void) noexcept;
66 void lock_shared(
void) noexcept;
69 void unlock_shared(
void) noexcept;
72 bool try_lock(
void) noexcept;
75 void lock(
void) noexcept;
78 void unlock(
void) noexcept;
81 enum :
unsigned {WRITER_LOCK = unsigned(~0), UNLOCKED = 0};
82 std::atomic<unsigned> _lock;
98 unsigned expected = _lock.load(std::memory_order_acquire);
99 return expected != WRITER_LOCK and _lock.compare_exchange_weak(expected, expected+1, std::memory_order_acq_rel);
105 while (not this->try_lock_shared())
107 if (++count > 1024) std::this_thread::yield();
114 _lock.fetch_sub(1, std::memory_order_release);
121 unsigned expected = UNLOCKED;
122 return _lock.compare_exchange_weak(expected, WRITER_LOCK, std::memory_order_acq_rel);
128 while (not this->try_lock())
130 if (++count > 1024) std::this_thread::yield();
137 _lock.store(UNLOCKED, std::memory_order_release);
void unlock(void) noexcept
Unlock single writer access.
Definition: SpinLockRW.hpp:134
#define POTHOS_API
Definition: Config.hpp:41
Pothos::Util::SharedLock< SpinLockRW > SharedLock
Convenient typedef for shared lock type.
Definition: SpinLockRW.hpp:57
Definition: ArchiveEntry.hpp:20
~SharedLock(void)
Definition: SpinLockRW.hpp:33
bool try_lock_shared(void) noexcept
Try to lock shared, return true for lock.
Definition: SpinLockRW.hpp:94
Definition: SpinLockRW.hpp:52
void lock(void) noexcept
Lock for single writer access.
Definition: SpinLockRW.hpp:125
void unlock_shared(void) noexcept
Unlock from multiple reader access.
Definition: SpinLockRW.hpp:111
void lock_shared(void) noexcept
Lock for multiple reader access.
Definition: SpinLockRW.hpp:102
SpinLockRW(void)
Create a new unlocked spin lock.
Definition: SpinLockRW.hpp:89
SharedLock(T &mutex)
Definition: SpinLockRW.hpp:27
Definition: SpinLockRW.hpp:24
bool try_lock(void) noexcept
Try to lock, return true for lock.
Definition: SpinLockRW.hpp:117