FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
sim_threading.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2006-2008 Marc Brooker and Michael Inggs
4// Copyright (c) 2008-present FERS Contributors (see AUTHORS.md).
5//
6// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
7
8/**
9 * @file sim_threading.h
10 * @brief Header file for the main simulation runner.
11 *
12 * This file contains the declarations for the high-level function that
13 * orchestrates and manages the event-driven radar simulation.
14 */
15
16#pragma once
17
18#include <functional>
19#include <mutex>
20#include <string>
21
22namespace pool
23{
24 class ThreadPool;
25}
26
27namespace core
28{
29 class World;
30
31 /**
32 * @class ProgressReporter
33 * @brief A thread-safe wrapper for the simulation progress callback.
34 *
35 * Allows multiple worker threads to report progress concurrently without race conditions.
36 */
38 {
39 public:
40 using Callback = std::function<void(const std::string&, int, int)>;
41
42 explicit ProgressReporter(Callback cb) : _callback(std::move(cb)) {}
43
44 void report(const std::string& msg, int current, int total)
45 {
46 if (_callback)
47 {
48 std::lock_guard<std::mutex> lock(_mutex);
49 _callback(msg, current, total);
50 }
51 }
52
53 private:
54 std::mutex _mutex;
55 Callback _callback;
56 };
57
58 /**
59 * @brief Runs the unified, event-driven radar simulation.
60 *
61 * This function is the core engine of the simulator. It advances time by
62 * processing events from a global priority queue. It handles both pulsed
63 * and continuous-wave (CW) physics, dispatching finalization tasks to
64 * worker threads for asynchronous processing.
65 *
66 * @param world A pointer to the simulation world containing all entities and state.
67 * @param pool A reference to the thread pool for executing tasks.
68 * @param progress_callback An optional callback function for reporting progress.
69 */
70 void runEventDrivenSim(World* world, pool::ThreadPool& pool,
71 const std::function<void(const std::string&, int, int)>& progress_callback);
72}
A thread-safe wrapper for the simulation progress callback.
ProgressReporter(Callback cb)
std::function< void(const std::string &, int, int)> Callback
void report(const std::string &msg, int current, int total)
A simple thread pool implementation.
Definition thread_pool.h:29
void runEventDrivenSim(World *world, pool::ThreadPool &pool, const std::function< void(const std::string &, int, int)> &progress_callback)
Runs the unified, event-driven radar simulation.