mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-08-02 17:31:53 +00:00
Add atomic signal implementation
This commit is contained in:
parent
b369f34092
commit
46cd2417e3
27
include/sta/atomic_signal.hpp
Normal file
27
include/sta/atomic_signal.hpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#ifndef STA_ATOMIC_SIGNAL_HPP
|
||||||
|
#define STA_ATOMIC_SIGNAL_HPP
|
||||||
|
|
||||||
|
#include <sta/signal.hpp>
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
|
|
||||||
|
namespace sta
|
||||||
|
{
|
||||||
|
class AtomicSignal : public Signal
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AtomicSignal();
|
||||||
|
|
||||||
|
void notify() override;
|
||||||
|
bool peek() override;
|
||||||
|
bool test() override;
|
||||||
|
void wait() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::atomic<bool> signal_;
|
||||||
|
};
|
||||||
|
} // namespace sta
|
||||||
|
|
||||||
|
|
||||||
|
#endif // STA_ATOMIC_SIGNAL_HPP
|
29
src/atomic_signal.cpp
Normal file
29
src/atomic_signal.cpp
Normal 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
|
Loading…
x
Reference in New Issue
Block a user