24 lines
313 B
C++
24 lines
313 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;
|
|
};
|
|
|
|
}}
|
|
|