2 #ifndef _YI_SPINLOCK_H_ 3 #define _YI_SPINLOCK_H_ 10 #ifndef YI_SPINLOCK_ATTEMPTS_BEFORE_YIELD 11 #define YI_SPINLOCK_ATTEMPTS_BEFORE_YIELD 10000 91 #if defined(_MSC_VER) && _MSC_VER <= 1800 // VS2013 or older. Non-static data member initializer is not implemented, and will be done in the constructor instead. 92 std::atomic_flag m_lock;
94 std::atomic_flag m_lock = ATOMIC_FLAG_INIT;
104 #if defined(_MSC_VER) && _MSC_VER <= 1800 // VS2013 or older. GCC and Clang atomic_flag implementations do not allow operator=. 115 if (!m_lock.test_and_set(std::memory_order_acquire))
120 std::this_thread::yield();
126 return !m_lock.test_and_set(std::memory_order_acquire);
131 m_lock.clear(std::memory_order_release);
bool TryLock()
Definition: YiSpinLock.h:124
#define YI_DISALLOW_COPY_AND_ASSIGN(TypeName)
Delete the copy constructor and assignment operator (and consequently the move constructor as well) ...
Definition: YiPredef.h:114
bool Unlock()
Definition: YiSpinLock.h:129
Provides access serialization between threads, where a thread trying to acquire the lock waits in a l...
Definition: YiSpinLock.h:65
CYISpinLock()
Definition: YiSpinLock.h:102
bool Lock()
Definition: YiSpinLock.h:109
#define YI_SPINLOCK_ATTEMPTS_BEFORE_YIELD
Definition: YiSpinLock.h:11