20 lines
667 B
C++
20 lines
667 B
C++
#pragma once
|
|
#include <atomic>
|
|
#include <cstdint>
|
|
namespace kcp {
|
|
class Spinlock {
|
|
std::atomic_flag f{ATOMIC_FLAG_INIT};
|
|
public:
|
|
void Acquire() { while (f.test_and_set(std::memory_order_acquire)) {} }
|
|
void Release() { f.clear(std::memory_order_release); }
|
|
};
|
|
// The kernel's Mutex is the non-interrupt-disabling variant; on the host
|
|
// there is nothing to disable, so the two are the same here.
|
|
class Mutex {
|
|
std::atomic_flag f{ATOMIC_FLAG_INIT};
|
|
public:
|
|
void Acquire() { while (f.test_and_set(std::memory_order_acquire)) {} }
|
|
void Release() { f.clear(std::memory_order_release); }
|
|
};
|
|
}
|