10#include <zephyr/kernel.h>
65 virtual void run() = 0;
93 shouldStop.store(
true, std::memory_order_release);
96 bool shouldRun()
const {
return !shouldStop.load(std::memory_order_acquire); }
114 k_thread_stack_t* stack{
nullptr};
115 std::atomic<bool> shouldStop{
false};
124 template <
typename T>
127 return (unit && unit->
getTypeId() == T::TYPE_ID) ?
static_cast<T*
>(unit) :
nullptr;
136 template <
typename T>
139 return (unit && unit->
getTypeId() == T::TYPE_ID) ?
static_cast<const T*
>(unit) :
nullptr;
143#define DEFINE_UNIT_DESCRIPTOR(TypeName, NameStr, DescStr, StackSize, Priority) \
144 static constexpr UnitTypeDescriptor descriptor{NameStr, DescStr, StackSize, Priority, typeNameHash(#TypeName)}; \
145 const UnitTypeDescriptor& typeDescriptor() const override { return descriptor; }
单元基类,定义了单元的基本行为和属性。
定义 Unit.hpp:46
void init()
定义 Unit.hpp:50
void tryStop()
定义 Unit.hpp:91
virtual void cleanupCustom()
定义 Unit.hpp:108
constexpr uint32_t getTypeId() const
定义 Unit.hpp:86
virtual void run()=0
单元的主运行函数。
constexpr std::string_view getDescription() const
定义 Unit.hpp:83
virtual const UnitTypeDescriptor & typeDescriptor() const =0
virtual void initCustom()
定义 Unit.hpp:107
void cleanup()
清理单元资源。
定义 Unit.hpp:72
constexpr std::string_view getName() const
定义 Unit.hpp:82
UnitRuntimeInfo stats
定义 Unit.hpp:99
constexpr size_t getStackSize() const
定义 Unit.hpp:84
UnitState state
定义 Unit.hpp:98
bool shouldRun() const
定义 Unit.hpp:96
constexpr uint8_t getPriority() const
定义 Unit.hpp:85
void StartUnits()
启动所有已注册的单元。
定义 Unit.cpp:72
T * unit_cast(Unit *unit)
安全的单元类型转换函数 (类似 dynamic_cast)。
定义 Unit.hpp:125
@ INITIALIZING
定义 Unit.hpp:32
@ UNINITIALIZED
定义 Unit.hpp:31
uint32_t cpuUsage
CPU 使用率
定义 Unit.hpp:25
uint32_t memoryUsage
内存使用量
定义 Unit.hpp:26
uint8_t priority
定义 Unit.hpp:19
size_t stackSize
定义 Unit.hpp:18
std::string_view description
定义 Unit.hpp:17
uint32_t typeId
定义 Unit.hpp:20
std::string_view name
定义 Unit.hpp:16