EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Loading...
Searching...
No Matches
Worker.hpp
Go to the documentation of this file.
1
7
8#ifndef ECHOMAP_WORKER_HPP
9#define ECHOMAP_WORKER_HPP
10
11#include <functional>
12#include <thread>
13
14#include "ThreadSafeQueue.hpp"
16#include "tasks/ITask.hpp"
17
18namespace echomap
19{
20
44class Worker
45{
46public:
47 using ResultCallback = std::function<void()>;
48
55
61 void submit(std::unique_ptr<ITask>&& task);
62
68 [[nodiscard]] bool is_result_available() const;
69
78
82 void clear();
83
84private:
90 void execute(const std::stop_token& stop_token) noexcept;
91
94
97};
98
99} // namespace echomap
100
101#endif // ECHOMAP_WORKER_HPP
Task description interface specification.
Thread-safe queue specification and implementation.
WorkerResult specification.
Provides a straightforward thread-safe double-ended queue implementation.
Worker(ResultCallback result_callback={})
Create a new Worker with an optional callback.
Definition Worker.cpp:17
std::function< void()> ResultCallback
The type of callback to indicate new results.
Definition Worker.hpp:47
ResultCallback result_callback
Callable to inform clients of new results.
Definition Worker.hpp:95
std::optional< WorkerResult > try_get_result()
Attempt to retrieve the latest WorkerResult object from the computation thread.
Definition Worker.cpp:40
bool is_result_available() const
Checks the state of the result queue.
Definition Worker.cpp:35
std::jthread worker_thread
RAII computation thread to handle ITask work pieces.
Definition Worker.hpp:96
void clear()
Clears any scheduled jobs or pending results.
Definition Worker.cpp:45
void execute(const std::stop_token &stop_token) noexcept
Executor running on the computation thread to receive work from the task queue and synchronously exec...
Definition Worker.cpp:51
void submit(std::unique_ptr< ITask > &&task)
Submit some work to the scheduler for execution on the computation thread.
Definition Worker.cpp:27
The main EchoMap outermost namespace for all non-exported symbols.