3 #include "SyncQueues.h"
16 typedef std::function<RT(StopCondition* const sc)>
Command;
46 , thread([=]() {
while ( !done ) {
49 DBOUT(L
"Active::thread ended"); }) {
59 std::future<RT>
Send(
const Command& _cmd) {
61 auto p = std::make_shared<std::promise<RT>>();
64 std::future<RT> ret = std::future<RT>(std::move(p->get_future()));
68 p->set_value(_cmd(sc));
82 if ( thread.joinable() )
84 DBOUT(L
"Active::Quitted\n");
void AbortCurrent()
Aborts the currently executed worker function.
Thread-safe lock-free bool to signal a requested stop to the worker function currently executed in th...
An active object implementation.
void Quit()
Send lambda with done=true to the worker, join the worker thread, and clear the packaged task queue...
void Enqueue(const T &elem)
Enqueues an element and notifies one waiting operation that queue is not empty.
std::function< RT(StopCondition *const sc)> Command
Type of the worker function to be executed in Active's thread.
Active()
The thread execution loop is created from a lambda.
std::future< RT > Send(const Command &_cmd)
Sends a worker function/packaged task to the queue to be executed in the Active's thread...
StopCondition stop
the abort signal
#define DBOUT(s)
A debug output to the debug console.
bool done
this is set to quit the worker thread
A synchronized, thread-safe queue was modeled after ringbuffer example from boost?! and/or a Herb Sutter column?!
void Set(const bool &_a=true)
SynchronizedQueue< const std::function< void(StopCondition *const sc)> > ptq
synchronized queue of worker functions/packaged tasks that are executed in the Active' thread (see la...
std::thread thread
a thread in which Run runs
void operator=(const Active &)
disable assignment
Various helper functions and classes for Scope.
T Dequeue()
Dequeues front element, waits indefinitely if queue is empty.