Files
snmalloc/src/ds/flaglock.h
David Chisnall 7eabea01d6 Add an Architecture Abstraction Layer.
Currently, we support one architecture, but this provides a layer for
adding other architectures without adding more nested `#ifdef`s.

Fixes #42
2019-07-10 10:42:59 +01:00

25 lines
371 B
C++

#pragma once
#include "bits.h"
namespace snmalloc
{
class FlagLock
{
private:
std::atomic_flag& lock;
public:
FlagLock(std::atomic_flag& lock) : lock(lock)
{
while (lock.test_and_set(std::memory_order_acquire))
AAL::pause();
}
~FlagLock()
{
lock.clear(std::memory_order_release);
}
};
} // namespace snmalloc