30#ifndef APF_COMMANDQUEUE_H
31#define APF_COMMANDQUEUE_H
76 virtual void execute() { }
77 virtual void cleanup() { _done =
true; }
104 inline void push(Command* cmd);
113 while ((cmd = _out_fifo.pop()) !=
nullptr) { _cleanup(cmd); }
124 if (_in_fifo.empty()) _active =
false;
132 assert(_in_fifo.empty());
148 while ((cmd = _in_fifo.pop()) !=
nullptr)
151 bool result = _out_fifo.push(cmd);
154 assert(result &&
"Error in _out_fifo.push()!");
163 return !_in_fifo.empty();
170 void _cleanup(Command* cmd)
172 assert(cmd !=
nullptr);
178 LockFreeFifo<Command*> _in_fifo;
180 LockFreeFifo<Command*> _out_fifo;
207 while (!_in_fifo.push(cmd))
210 assert(
false &&
"Error in _in_fifo.push()!");
212 std::this_thread::sleep_for(std::chrono::microseconds(50));
228 std::this_thread::sleep_for(std::chrono::microseconds(50));
Dummy command to synchronize with non-realtime thread.
WaitCommand(bool &done)
Constructor.
Manage command queue from non-realtime thread to realtime thread.
~CommandQueue()
Destructor.
void cleanup_commands()
Clean up all commands in the cleanup-queue.
void process_commands()
Execute all commands in the queue.
bool deactivate()
Deactivate queue; process following commands in the non-realtime thread.
void push(Command *cmd)
Push a command to be executed in the realtime thread.
CommandQueue(size_t size)
Constructor.
void wait()
Wait for realtime thread.
void reactivate()
Re-activate queue.
bool commands_available() const
Check if commands are available.
Classes derived from this class cannot be copied (but still moved).
Lock-free first-in-first-out queue.
Audio Processing Framework.
Abstract base class for realtime commands.
virtual void cleanup()=0
Cleanup of resources.
virtual void execute()=0
The actual implementation of the command.
virtual ~Command()
Empty virtual destructor.