Move atomic implementations

This commit is contained in:
Henrik Stickann
2022-04-10 20:36:46 +02:00
parent 46cd2417e3
commit 4bf8a31acf
4 changed files with 2 additions and 2 deletions

19
src/atomic/mutex.cpp Normal file
View File

@@ -0,0 +1,19 @@
#include <sta/atomic/mutex.hpp>
namespace sta
{
AtomicMutex::AtomicMutex()
: lock_{ATOMIC_FLAG_INIT}
{}
void AtomicMutex::acquire()
{
while (lock_.test_and_set());
}
void AtomicMutex::release()
{
lock_.clear();
}
} // namespace sta

29
src/atomic/signal.cpp Normal file
View File

@@ -0,0 +1,29 @@
#include <sta/atomic/signal.hpp>
namespace sta
{
AtomicSignal::AtomicSignal()
: signal_{false}
{}
void AtomicSignal::notify()
{
signal_.store(true);
}
bool AtomicSignal::peek()
{
return signal_.load();
}
bool AtomicSignal::test()
{
return signal_.exchange(false);
}
void AtomicSignal::wait()
{
while (!signal_.exchange(false));
}
} // namespace sta