libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
thread.hpp
1#pragma once
2
3#include "libxr_def.hpp"
4#include "libxr_system.hpp"
5#include "libxr_time.hpp"
6
7namespace LibXR
8{
9
15class Thread
16{
17 public:
22 enum class Priority
23 {
24 IDLE = 0,
25 LOW = 0,
26 MEDIUM = 0,
27 HIGH = 0,
28 REALTIME = 0,
29 NUMBER = 1,
30 };
31
36 Thread() {};
37
44
64 template <typename ArgType>
65 void Create(ArgType arg, void (*function)(ArgType arg), const char *name,
67 {
68 UNUSED(name);
69 UNUSED(stack_depth);
70 UNUSED(priority);
71
72 static bool created = false;
73 ASSERT(created == false);
74 created = true;
75 UNUSED(created);
76
77 function(arg);
78 }
79
85 static Thread Current(void);
86
92 static uint32_t GetTime();
93
100
108
113 static void Yield();
114
120 operator libxr_thread_handle() { return thread_handle_; }
121
122 private:
124};
125
126} // namespace LibXR
线程管理类,封装 FreeRTOS 任务创建和调度 Thread management class encapsulating FreeRTOS task creation and scheduling
Definition thread.hpp:15
Thread(libxr_thread_handle handle)
通过线程句柄创建线程对象 Constructor to create a thread object from a thread handle
Definition thread.hpp:43
static void Sleep(uint32_t milliseconds)
让线程进入休眠状态 Puts the thread to sleep
Thread()
默认构造函数,初始化空线程对象 Default constructor initializing an empty thread object
Definition thread.hpp:36
Priority
线程优先级枚举 Enumeration for thread priorities
Definition thread.hpp:22
@ NUMBER
优先级数量 Number of priority levels
@ LOW
低优先级 Low priority
@ REALTIME
实时优先级 Realtime priority
@ IDLE
空闲优先级 Idle priority
@ HIGH
高优先级 High priority
@ MEDIUM
中等优先级 Medium priority
libxr_thread_handle thread_handle_
FreeRTOS 线程句柄 FreeRTOS thread handle.
Definition thread.hpp:136
void Create(ArgType arg, void(*function)(ArgType arg), const char *name, size_t stack_depth, Thread::Priority priority)
创建并执行新线程 Creates and executes a new thread
Definition thread.hpp:65
static void Yield()
让出 CPU 以执行其他线程 Yields CPU execution to allow other threads to run
static uint32_t GetTime()
获取当前系统时间(毫秒) Gets the current system time in milliseconds
static void SleepUntil(TimestampMS &last_waskup_time, uint32_t time_to_sleep)
让线程休眠直到指定时间点 Puts the thread to sleep until a specified time
static Thread Current(void)
获取当前线程对象 Gets the current thread object
表示毫秒级时间戳的类。Class representing a timestamp in milliseconds.
LibXR Color Control Library / LibXR终端颜色控制库
TaskHandle_t libxr_thread_handle
线程句柄类型定义 Thread handle type definition
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值