19 #ifndef COM_BORA_SOFTWARE__BALAU_CONCURRENT__SINGLE_TIME_EXECUTOR 20 #define COM_BORA_SOFTWARE__BALAU_CONCURRENT__SINGLE_TIME_EXECUTOR 39 : code(
std::move(code_))
50 : code(
std::move(code_))
51 , destructorCode(
std::move(destructorCode_)) {}
57 bool isExecuted = executed.load(std::memory_order_relaxed);
58 std::atomic_thread_fence(std::memory_order_acquire);
61 std::lock_guard<std::mutex> lock(mutex);
62 isExecuted = executed.load(std::memory_order_relaxed);
64 if (isExecuted && destructorCode) {
74 bool isExecuted = executed.load(std::memory_order_relaxed);
75 std::atomic_thread_fence(std::memory_order_acquire);
78 std::lock_guard<std::mutex> lock(mutex);
79 isExecuted = executed.load(std::memory_order_relaxed);
81 if (!isExecuted && code) {
83 std::atomic_thread_fence(std::memory_order_release);
84 executed.store(
true, std::memory_order_relaxed);
114 private: std::function<void ()> code;
115 private: std::function<void ()> destructorCode;
116 private: std::atomic<bool> executed;
117 private: std::mutex mutex;
122 #endif // COM_BORA_SOFTWARE__BALAU_CONCURRENT__SINGLE_TIME_EXECUTOR SingleTimeExecutor(std::function< void()> code_, std::function< void()> destructorCode_)
Create a single time executor with a code block and a destructor code block.
Definition: SingleTimeExecutor.hpp:49
void operator()()
Execute the code a single time.
Definition: SingleTimeExecutor.hpp:73
Concurrency control classes.
Definition: CyclicBarrier.hpp:26
bool hasExecuted() const
Returns true if the code has been executed.
Definition: SingleTimeExecutor.hpp:99
Executes the supplied code block a single time.
Definition: SingleTimeExecutor.hpp:34
~SingleTimeExecutor()
Destroy the single time executor.
Definition: SingleTimeExecutor.hpp:56
std::mutex & getMutex()
Get the internal mutex in order to synchronise on external code.
Definition: SingleTimeExecutor.hpp:108
SingleTimeExecutor(std::function< void()> code_)
Create a single time executor with a code block.
Definition: SingleTimeExecutor.hpp:38