3#include <EASTL/unique_ptr.h>
4#include <EASTL/string.h>
5#include <SFML/System.hpp>
33 std::chrono::steady_clock::time_point
startTime, endTime;
92 void launch(
const eastl::string& name);
139 void cleanupFinishedUnlocked();
142 mutable std::mutex mutex;
144 eastl::unordered_map<Thread*, ThreadInfo> threads;
146 eastl::vector<eastl::unique_ptr<Thread>> threadStorage;
152 auto thread = eastl::make_unique<Thread>(qBus, [
this, func, name]() {
157 Thread* rawThread = thread.get();
159 std::lock_guard<std::mutex> lock(mutex);
161 ti.
startTime = std::chrono::steady_clock::now();
166 threads.emplace(rawThread, ti);
168 threadStorage.push_back(eastl::move(thread));
174 auto thread = eastl::make_unique<Thread>(
180 Thread* rawThread = thread.get();
182 std::lock_guard<std::mutex> lock(mutex);
186 std::chrono::steady_clock::now(),
192 threadStorage.push_back(eastl::move(thread));
High-level Thread wrapper and callable adapters used by the project.
Thread-safe event bus.
Definition QEventBus.hpp:58
Lightweight high-level thread wrapper.
Definition Thread.hpp:134
Thread * createThread(const eastl::string &name, F func)
Create (and store) a Thread from a generic callable.
Definition ThreadManager.hpp:151
ThreadManager(QEventBus &qBus)
Construct a ThreadManager bound to a QEventBus.
Definition ThreadManager.cpp:5
~ThreadManager()
Destructor cleans up managed threads and subscriptions.
Definition ThreadManager.cpp:14
void waitAll()
Block until all managed threads have finished executing.
Definition ThreadManager.cpp:39
void launch(Thread *th)
Launch a previously created Thread instance.
Definition ThreadManager.cpp:17
size_t activeCount() const
Count of currently active (non-finished) threads.
Definition ThreadManager.cpp:62
void printStats()
Print statistics (e.g. runtime durations) for managed threads.
Definition ThreadManager.cpp:52
void cleanupFinished()
Remove and cleanup finished threads from internal storage.
Definition ThreadManager.cpp:47
Metadata stored per managed thread.
Definition ThreadManager.hpp:27
bool finished
True when the thread has finished execution.
Definition ThreadManager.hpp:35
std::chrono::steady_clock::time_point startTime
Time point when the thread was started.
Definition ThreadManager.hpp:33
eastl::string name
Human readable thread name.
Definition ThreadManager.hpp:31
Thread * thread
Non-owning pointer to the tracked Thread.
Definition ThreadManager.hpp:29