EchoMap
2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Toggle main menu visibility
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
"
15
#include "
results/WorkerResult.hpp
"
16
#include "
tasks/ITask.hpp
"
17
18
namespace
echomap
19
{
20
44
class
Worker
45
{
46
public
:
47
using
ResultCallback
=
std::function
<void()>;
48
54
explicit
Worker
(
ResultCallback
result_callback
= {});
55
61
void
submit
(
std::unique_ptr<ITask>
&& task);
62
68
[[nodiscard]]
bool
is_result_available
()
const
;
69
77
std::optional<WorkerResult>
try_get_result
();
78
82
void
clear
();
83
84
private
:
90
void
execute
(
const
std::stop_token
& stop_token)
noexcept
;
91
92
ThreadSafeQueue<std::unique_ptr<ITask>
> task_queue;
93
ThreadSafeQueue<WorkerResult>
result_queue;
94
95
ResultCallback
result_callback
;
96
std::jthread
worker_thread
;
97
};
98
99
}
// namespace echomap
100
101
#endif
// ECHOMAP_WORKER_HPP
ITask.hpp
Task description interface specification.
ThreadSafeQueue.hpp
Thread-safe queue specification and implementation.
WorkerResult.hpp
WorkerResult specification.
echomap::ThreadSafeQueue
Provides a straightforward thread-safe double-ended queue implementation.
Definition
ThreadSafeQueue.hpp:30
echomap::Worker::Worker
Worker(ResultCallback result_callback={})
Create a new Worker with an optional callback.
Definition
Worker.cpp:17
echomap::Worker::ResultCallback
std::function< void()> ResultCallback
The type of callback to indicate new results.
Definition
Worker.hpp:47
echomap::Worker::result_callback
ResultCallback result_callback
Callable to inform clients of new results.
Definition
Worker.hpp:95
echomap::Worker::try_get_result
std::optional< WorkerResult > try_get_result()
Attempt to retrieve the latest WorkerResult object from the computation thread.
Definition
Worker.cpp:40
echomap::Worker::is_result_available
bool is_result_available() const
Checks the state of the result queue.
Definition
Worker.cpp:35
echomap::Worker::worker_thread
std::jthread worker_thread
RAII computation thread to handle ITask work pieces.
Definition
Worker.hpp:96
echomap::Worker::clear
void clear()
Clears any scheduled jobs or pending results.
Definition
Worker.cpp:45
echomap::Worker::execute
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
echomap::Worker::submit
void submit(std::unique_ptr< ITask > &&task)
Submit some work to the scheduler for execution on the computation thread.
Definition
Worker.cpp:27
std::function
functional
std::jthread
echomap
The main EchoMap outermost namespace for all non-exported symbols.
Definition
ActionController.hpp:20
std::optional
std::stop_token
thread
std::unique_ptr
src
async
Worker.hpp
Generated by
1.17.0