|
libstp
Robotics library for Botball
|
#include <thread_manager.hpp>
Classes | |
| class | DaemonHandle |
Public Member Functions | |
| DaemonHandle | add_daemon (std::string name, DaemonFn fn) |
| void | add_persistent_daemon (std::string name, DaemonFn fn) |
| void | shutdown () |
| std::size_t | daemon_count () const |
| Number of currently-registered daemons. Test helper. | |
| ~ThreadManager () | |
| ThreadManager (const ThreadManager &)=delete | |
| ThreadManager & | operator= (const ThreadManager &)=delete |
Static Public Member Functions | |
| static ThreadManager & | instance () |
Friends | |
| class | DaemonHandle |
Process-wide registry for background threads.
Every long-lived worker in raccoon-lib goes through this singleton — nothing constructs a bare std::thread of its own. There are two lifetimes:
Both flavours observe the same std::stop_token contract — daemons must return when the token is requested.
Definition at line 35 of file thread_manager.hpp.
| libstp::threading::ThreadManager::~ThreadManager | ( | ) |
|
delete |
|
nodiscard |
Register a scoped daemon. The caller owns the returned handle; dropping it stops and joins the thread. Calling this after shutdown() returns an empty handle and logs a warning.
| void libstp::threading::ThreadManager::add_persistent_daemon | ( | std::string | name, |
| DaemonFn | fn ) |
Register a process-lifetime daemon. Joined at shutdown() time. Use this only when the thread must live as long as the library itself does — otherwise prefer add_daemon.
|
nodiscard |
Number of currently-registered daemons. Test helper.
|
static |
|
delete |
| void libstp::threading::ThreadManager::shutdown | ( | ) |
Request stop on every registered daemon (persistent and scoped) and join them. Idempotent; safe to call from the singleton destructor and from teardown helpers in tests.
|
friend |
Definition at line 65 of file thread_manager.hpp.