线程配置
公共头文件: #include "brookesia/lib_utils/thread_config.hpp"
概述
thread_config 提供线程运行参数的统一配置能力,并通过 RAII 守卫在作用域内 自动应用与恢复线程配置。
特性
提供 ThreadConfig 结构体,统一管理名称、优先级、栈大小、核心绑定等
支持从系统默认配置或当前线程配置读取并应用
ThreadConfigGuard 作用域内自动恢复原配置
提供便捷宏用于配置与查询线程参数
API 参考
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.
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
- 参数
... – 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());
备注
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.
- 返回
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());
备注
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.
- 返回
ThreadConfigcontaining the active pthread defaults. When no override was applied, the system default configuration is returned.