|
sas
Modularised monitoring, logging, and control of robots.
|
Public Types | |
| enum class | PRIORITY { LOWEST = 0 , BACKGROUND = 10 , NORMAL = 50 , HIGH = 80 , REALTIME = 90 , CRITICAL = 99 } |
| Abstract priority levels for thread_manager threads. More... | |
Public Member Functions | |
| ~ThreadManager () | |
| ThreadManager::~ThreadManager destructor of the class. | |
| ThreadManager (const ThreadManager &)=delete | |
| ThreadManager & | operator= (const ThreadManager &)=delete |
| ThreadManager (ThreadManager &&)=delete | |
| ThreadManager & | operator= (ThreadManager &&)=delete |
| ThreadManager (const std::string &thread_name, const double &period, std::function< void()> callback, PRIORITY priority=PRIORITY::NORMAL, int cpu_core=-1) | |
| Constructor for ThreadManager. | |
| const marinholab::sas::core::Clock & | get_clock () const |
| Get a const reference to the internal clock instance. | |
| void | start () |
| Start the thread execution. | |
| void | stop () |
| Stop the thread execution and wait for completion. | |
| bool | is_running () const |
| Check if the thread is currently running. | |
| std::string | get_thread_name () const |
| Get the thread name. | |
| PRIORITY | get_priority () const |
| Get the priority level of this thread. | |
| int | get_cpu_core () const |
| Get the CPU core that this thread is pinned to. | |
| double | get_period () const |
| Get the desired loop period (sampling time). | |
Protected Member Functions | |
| void | run () |
| Main thread entry function. | |
Protected Attributes | |
| marinholab::sas::core::Clock | clock_ |
| std::function< void()> | loop_callback_ |
| std::thread | thread_ |
| std::string | thread_name_ |
| std::atomic< bool > | running_ {false} |
| std::atomic< bool > | stop_requested_ {false} |
|
strong |
Abstract priority levels for thread_manager threads.
These levels are mapped to concrete Linux scheduling policies and priority/nice values in apply_priority(). The enum values themselves (0, 10, 50, 80, 90, 99) are NOT passed directly to the OS in most cases — they exist purely to establish a monotonic ordering (LOWEST < ... CRITICAL) that is easy to read and compare in application code. The actual OS-level values used for each level are documented per-enumerator below, and are applied in sas_thread_manager.cpp.
Linux scheduling background:
| marinholab::sas::core::ThreadManager::ThreadManager | ( | const std::string & | thread_name, |
| const double & | period, | ||
| std::function< void()> | callback, | ||
| PRIORITY | priority = PRIORITY::NORMAL, | ||
| int | cpu_core = -1 ) |
Constructor for ThreadManager.
Creates a thread manager that executes a callback function periodically with configurable priority and CPU affinity.
| thread_name | Name of the thread for identification and debugging. On Linux, names are truncated to 15 characters. |
| period | Period in seconds between callback executions. Must be greater than 0.0. |
| callback | Function to call periodically. The callback should be thread-safe and should not block for extended periods to avoid missing deadlines. |
| priority | Thread priority level (default: PRIORITY::NORMAL). Higher priorities get more CPU time:
|
| cpu_core | CPU core to pin the thread to (-1 = no affinity, default). Pinning to a specific core improves cache locality and reduces context switching for real-time applications. |
| std::invalid_argument | if period <= 0.0. |
| const marinholab::sas::core::Clock & marinholab::sas::core::ThreadManager::get_clock | ( | ) | const |
Get a const reference to the internal clock instance.
Provides access to the clock that manages timing, performance monitoring, and statistics collection for this thread. This is useful for:
| int marinholab::sas::core::ThreadManager::get_cpu_core | ( | ) | const |
Get the CPU core that this thread is pinned to.
| double marinholab::sas::core::ThreadManager::get_period | ( | ) | const |
Get the desired loop period (sampling time).
Returns the target period configured at construction time.
| ThreadManager::PRIORITY marinholab::sas::core::ThreadManager::get_priority | ( | ) | const |
Get the priority level of this thread.
| std::string marinholab::sas::core::ThreadManager::get_thread_name | ( | ) | const |
Get the thread name.
| bool marinholab::sas::core::ThreadManager::is_running | ( | ) | const |
Check if the thread is currently running.