22 lines
352 B
C++
22 lines
352 B
C++
#pragma once
|
|
|
|
#include <atomic>
|
|
|
|
namespace bts {
|
|
namespace utils {
|
|
|
|
class SpinLock {
|
|
public:
|
|
void lock() {
|
|
while (_mutex.test_and_set(std::memory_order_acquire))
|
|
;
|
|
}
|
|
void unlock() { _mutex.clear(std::memory_order_release); }
|
|
|
|
private:
|
|
std::atomic_flag _mutex = ATOMIC_FLAG_INIT;
|
|
};
|
|
|
|
} // namespace utils
|
|
} // namespace bts
|