Files
snmalloc/src/ds/flaglock.h
Matthew Parkinson 20a114cb62 Add a timer to the PAL
This adds a way to periodically pool the PAL to see if any timers have
expired.  Timers can be used to periodically provide callbacks to the
rest of snmalloc.
2021-10-28 14:28:36 +01:00

27 lines
390 B
C++

#pragma once
#include "bits.h"
#include <atomic>
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