Thread Configuration
Public header: #include "brookesia/lib_utils/thread_config.hpp"
Overview
thread_config centralizes thread runtime parameters and uses RAII guards to apply and restore settings in a scope.
Features
ThreadConfig for name, priority, stack, core affinity
Read defaults or current thread settings
ThreadConfigGuard restores previous config on scope exit
Convenience macros for configuration and queries
API Reference
Header File
Classes
-
class ThreadConfigGuard
RAII guard for thread configuration.
This class provides automatic restoration of thread configuration. When constructed, it applies the new configuration and saves the original. When destroyed, it restores the original configuration.
Public Functions
-
ThreadConfigGuard(const ThreadConfig &config)
Apply a new thread configuration and remember the previous one.
- Parameters
config – [in] Thread configuration to apply for the lifetime of this guard.
-
~ThreadConfigGuard()
Restore the thread configuration that was active before construction.
-
ThreadConfigGuard(const ThreadConfig &config)
Macros
-
_BROOKESIA_THREAD_CONFIG_CONCAT(a, b)
-
BROOKESIA_THREAD_CONFIG_CONCAT(a, b)
-
BROOKESIA_THREAD_CONFIG_GUARD(...)
Apply a temporary thread configuration for the current scope.
This macro creates a
ThreadConfigGuardinstance that restores the previous configuration automatically when the surrounding scope exits.{ BROOKESIA_THREAD_CONFIG_GUARD({ .stack_size = 10 * 1024, }); boost::thread([&]() { // Thread will be created with 10KB stack size }); } // Original configuration is restored here
- Parameters
... – Arguments forwarded to the
ThreadConfigGuardconstructor.
-
BROOKESIA_THREAD_GET_CURRENT_CONFIG()
Query the runtime configuration of the current task.
BROOKESIA_LOGI("Current task: %1%", BROOKESIA_THREAD_GET_CURRENT_CONFIG());
Note
This returns the actual runtime configuration of the current FreeRTOS task, which may differ from the applied pthread configuration if the task was created directly via FreeRTOS APIs rather than pthread APIs.
- Returns
ThreadConfigcontaining the current task’s runtime configuration.
-
BROOKESIA_THREAD_GET_APPLIED_CONFIG()
Query the pthread configuration currently applied to newly created threads.
BROOKESIA_LOGI("Applied task: %1%", BROOKESIA_THREAD_GET_APPLIED_CONFIG());
Note
This returns the applied pthread configuration, which may differ from the actual runtime configuration of existing tasks. Use BROOKESIA_THREAD_GET_CURRENT_CONFIG() to get the actual runtime state of the current task.
- Returns
ThreadConfigcontaining the active pthread defaults. When no override was applied, the system default configuration is returned.