XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
xwos::SThd< TCpu > 模板类 参考

静态线程 更多...

#include <SThd.hxx>

xwos::SThd< TCpu > 的协作图:

Public 成员函数

 SThd (const char *name, xwstk_t *stack, xwsz_t stack_size, xwsz_t stack_guard_size=XWOS_STACK_GUARD_SIZE_DEFAULT, xwpr_t priority=XWOS_SKD_PRIORITY_RT_MIN, bool detached=false, bool privileged=true)
 静态线程构造函数
 
virtual ~SThd ()
 静态线程析构函数
 
xwer_t launch ()
 加载线程
 
xwer_t getStackInfo (struct xwos_thd_stack_info *stack)
 获取当前线程的栈信息
 
xwer_t intr ()
 中断线程的阻塞态和睡眠态
 
xwer_t quit ()
 通知线程退出
 
xwer_t join (xwer_t *trc)
 等待线程结束并获取它的返回值
 
xwer_t stop (xwer_t *trc)
 通知线程退出,等待线程结束并获取它的返回值
 
xwer_t detach ()
 终止线程并等待它退出
 
struct xwos_thdgetXwosObj ()
 获取XWOS对象指针
 
xwer_t grab ()
 
xwer_t put ()
 

Protected 成员函数

virtual xwer_t thdMainFunction ()
 线程主函数,用户需要重新实现此函数
 
void yield ()
 当前线程通知调度器重新调度
 
void exit (xwer_t rc)
 退出当前线程
 
bool shouldFreeze ()
 判断当前线程是否可被冻结
 
bool shouldStop ()
 判断当前线程是否可以退出
 
xwer_t sleep (xwtm_t dur)
 当前线程睡眠一段时间
 
xwer_t sleepTo (xwtm_t to)
 当前线程睡眠到一个时间点
 
xwer_t sleepFrom (xwtm_t *from, xwtm_t dur)
 当前线程从一个时间起点睡眠到另一个时间点
 
xwer_t freeze (void)
 冻结当前线程
 

静态 Private 成员函数

static xwer_t sThdMainFunction (SThd *thd)
 

Private 属性

xwos_thd_d mThdDesc
 
struct xwos_thd mThd
 

详细描述

template<xwid_t TCpu = 0UL>
class xwos::SThd< TCpu >

静态线程

参数
[in]TCpu目标CPU

在文件 SThd.hxx39 行定义.

构造及析构函数说明

◆ SThd()

template<xwid_t TCpu = 0UL>
xwos::SThd< TCpu >::SThd ( const char *  name,
xwstk_t stack,
xwsz_t  stack_size,
xwsz_t  stack_guard_size = XWOS_STACK_GUARD_SIZE_DEFAULT,
xwpr_t  priority = XWOS_SKD_PRIORITY_RT_MIN,
bool  detached = false,
bool  privileged = true 
)
inline

静态线程构造函数

参数
[in]name线程名
[in]stack线程栈内存
[in]stack_size线程栈的大小
[in]stack_guard_size栈内存警戒线位置
[in]priority优先级
[in]detached是否为分离态
[in]privileged是否为特权线程

在文件 SThd.hxx56 行定义.

60 : mThdDesc{ nullptr, 0 }
61 {
62 struct xwos_thd_attr attr({
63 .name = name,
64 .stack = stack,
65 .stack_size = stack_size,
66 .stack_guard_size = stack_guard_size,
67 .priority = priority,
68 .detached = detached,
69 .privileged = privileged,
70 });
71 xwos_thd_init(&mThd, &mThdDesc, &attr, nullptr, nullptr);
72 }
struct xwos_thd mThd
Definition SThd.hxx:43
xwos_thd_d mThdDesc
Definition SThd.hxx:42
static xwer_t xwos_thd_init(struct xwos_thd *thd, xwos_thd_d *thdd, const struct xwos_thd_attr *attr, xwos_thd_f thdfunc, void *arg)
XWOS API:静态方式初始化线程
Definition thd.h:294
XWOS API:线程属性
Definition thd.h:171
函数调用图:

◆ ~SThd()

template<xwid_t TCpu = 0UL>
virtual xwos::SThd< TCpu >::~SThd ( )
inlinevirtual

静态线程析构函数

在文件 SThd.hxx76 行定义.

static xwer_t xwos_thd_detach(xwos_thd_d thdd)
XWMP API:分离线程
Definition thd.h:622
函数调用图:

成员函数说明

◆ launch()

template<xwid_t TCpu = 0UL>
xwer_t xwos::SThd< TCpu >::launch ( )
inline

加载线程

返回
错误码
返回值
XWOK没有错误
-EHOSTUNREACHCPU不匹配
注解
  • 上下文:任意

线程会在调用此C++API的CPU上开始运行。

在文件 SThd.hxx87 行定义.

88 {
89 xwer_t rc;
90
91 if (TCpu == Cpu::getLocalCpuId()) {
93 } else {
94 rc = -EHOSTUNREACH;
95 }
96 return rc;
97 }
static xwid_t getLocalCpuId()
获取当前CPU的ID
Definition Cpu.hxx:64
static xwer_t sThdMainFunction(SThd *thd)
Definition SThd.hxx:214
#define EHOSTUNREACH
Host is unreachable
Definition errno.h:131
signed long xwer_t
Definition type.h:554
xwer_t(* xwos_thd_f)(void *)
XWOS API:线程函数指针类型
Definition thd.h:153
static xwer_t xwos_thd_launch(xwos_thd_d thdd, xwos_thd_f thdfunc, void *arg)
XWOS API:加载线程
Definition thd.h:422
函数调用图:

◆ getStackInfo()

template<xwid_t TCpu = 0UL>
xwer_t xwos::SThd< TCpu >::getStackInfo ( struct xwos_thd_stack_info stack)
inline

获取当前线程的栈信息

参数
[out]stack用于返回线程栈信息的缓冲区

在文件 SThd.hxx102 行定义.

103 {
104 return xwos_thd_get_stack_info(mThdDesc, stack);
105 }
static xwer_t xwos_thd_get_stack_info(xwos_thd_d thdd, struct xwos_thd_stack_info *stack)
XWOS API:获取线程的栈信息
Definition thd.h:460
函数调用图:

◆ intr()

template<xwid_t TCpu = 0UL>
xwer_t xwos::SThd< TCpu >::intr ( )
inline

中断线程的阻塞态和睡眠态

在文件 SThd.hxx109 行定义.

109{ return xwos_thd_intr(mThdDesc); }
static xwer_t xwos_thd_intr(xwos_thd_d thdd)
XWOS API:中断线程的阻塞态和睡眠态
Definition thd.h:511
函数调用图:

◆ quit()

template<xwid_t TCpu = 0UL>
xwer_t xwos::SThd< TCpu >::quit ( )
inline

通知线程退出

在文件 SThd.hxx113 行定义.

113{ return xwos_thd_quit(mThdDesc); }
static xwer_t xwos_thd_quit(xwos_thd_d thdd)
XWOS API:通知线程退出
Definition thd.h:542
函数调用图:

◆ join()

template<xwid_t TCpu = 0UL>
xwer_t xwos::SThd< TCpu >::join ( xwer_t trc)
inline

等待线程结束并获取它的返回值

在文件 SThd.hxx117 行定义.

118 {
119 return xwos_thd_join(mThdDesc, trc);
120 }
static xwer_t xwos_thd_join(xwos_thd_d thdd, xwer_t *trc)
XWOS API:等待线程结束,回收线程内存资源,抛出它的返回值
Definition thd.h:577
函数调用图:

◆ stop()

template<xwid_t TCpu = 0UL>
xwer_t xwos::SThd< TCpu >::stop ( xwer_t trc)
inline

通知线程退出,等待线程结束并获取它的返回值

在文件 SThd.hxx124 行定义.

125 {
126 return xwos_thd_stop(mThdDesc, trc);
127 }
static xwer_t xwos_thd_stop(xwos_thd_d thdd, xwer_t *trc)
XWOS API:终止线程并等待它退出,回收线程内存资源,并抛出线程的返回值
Definition thd.h:600
函数调用图:

◆ detach()

template<xwid_t TCpu = 0UL>
xwer_t xwos::SThd< TCpu >::detach ( )
inline

终止线程并等待它退出

在文件 SThd.hxx131 行定义.

131{ return xwos_thd_detach(mThdDesc); }
函数调用图:

◆ getXwosObj()

template<xwid_t TCpu = 0UL>
struct xwos_thd * xwos::SThd< TCpu >::getXwosObj ( )
inline

获取XWOS对象指针

在文件 SThd.hxx135 行定义.

135{ return mThdDesc.thd; }
struct xwos_thd * thd
Definition thd.h:159

◆ grab()

template<xwid_t TCpu = 0UL>
xwer_t xwos::SThd< TCpu >::grab ( )
inline

增加引用计数

在文件 SThd.hxx138 行定义.

函数调用图:

◆ put()

template<xwid_t TCpu = 0UL>
xwer_t xwos::SThd< TCpu >::put ( )
inline

减少引用计数

在文件 SThd.hxx139 行定义.

函数调用图:

◆ thdMainFunction()

template<xwid_t TCpu = 0UL>
virtual xwer_t xwos::SThd< TCpu >::thdMainFunction ( )
inlineprotectedvirtual

线程主函数,用户需要重新实现此函数

在文件 SThd.hxx146 行定义.

146{ return XWOK; }
#define XWOK
No error
Definition errno.h:182
这是这个函数的调用关系图:

◆ yield()

template<xwid_t TCpu = 0UL>
void xwos::SThd< TCpu >::yield ( )
inlineprotected

当前线程通知调度器重新调度

在文件 SThd.hxx152 行定义.

153 {
155 }
static void xwos_cthd_yield(void)
XWOS API:当前线程通知调度器重新调度
Definition thd.h:712
函数调用图:

◆ exit()

template<xwid_t TCpu = 0UL>
void xwos::SThd< TCpu >::exit ( xwer_t  rc)
inlineprotected

退出当前线程

参数
[in]rc线程退出时抛出的返回值

在文件 SThd.hxx160 行定义.

161 {
162 xwos_cthd_exit(rc);
163 }
static void xwos_cthd_exit(xwer_t rc)
XWOS API:退出当前线程
Definition thd.h:727
函数调用图:

◆ shouldFreeze()

template<xwid_t TCpu = 0UL>
bool xwos::SThd< TCpu >::shouldFreeze ( )
inlineprotected

判断当前线程是否可被冻结

在文件 SThd.hxx167 行定义.

168 {
169 return xwos_cthd_shld_frz();
170 }
static bool xwos_cthd_shld_frz(void)
XWOS API:判断当前线程是否可被冻结
Definition thd.h:741
函数调用图:

◆ shouldStop()

template<xwid_t TCpu = 0UL>
bool xwos::SThd< TCpu >::shouldStop ( )
inlineprotected

判断当前线程是否可以退出

在文件 SThd.hxx174 行定义.

175 {
176 return xwos_cthd_shld_stop();
177 }
static bool xwos_cthd_shld_stop(void)
XWOS API:判断当前线程是否可以退出
Definition thd.h:767
函数调用图:

◆ sleep()

template<xwid_t TCpu = 0UL>
xwer_t xwos::SThd< TCpu >::sleep ( xwtm_t  dur)
inlineprotected

当前线程睡眠一段时间

参数
[in]dur期望睡眠的时间

在文件 SThd.hxx182 行定义.

183 {
184 return xwos_cthd_sleep(dur);
185 }
static xwer_t xwos_cthd_sleep(xwtm_t dur)
XWOS API:当前线程睡眠一段时间
Definition thd.h:827
函数调用图:

◆ sleepTo()

template<xwid_t TCpu = 0UL>
xwer_t xwos::SThd< TCpu >::sleepTo ( xwtm_t  to)
inlineprotected

当前线程睡眠到一个时间点

参数
[in]to期望唤醒的时间点

在文件 SThd.hxx190 行定义.

191 {
192 return xwos_cthd_sleep_to(to);
193 }
static xwer_t xwos_cthd_sleep_to(xwtm_t to)
XWOS API:线程睡眠到一个时间点
Definition thd.h:850
函数调用图:

◆ sleepFrom()

template<xwid_t TCpu = 0UL>
xwer_t xwos::SThd< TCpu >::sleepFrom ( xwtm_t from,
xwtm_t  dur 
)
inlineprotected

当前线程从一个时间起点睡眠到另一个时间点

参数
[in,out]from指向缓冲区的指针,此缓冲区:
  • (I) 输入时,作为时间起点
  • (O) 输出时,返回线程被唤醒的时间(可作为下一次时间起点)
[in]dur期望被唤醒的时间增量(相对于时间原点)

在文件 SThd.hxx201 行定义.

202 {
203 return xwos_cthd_sleep_from(from, dur);
204 }
static xwer_t xwos_cthd_sleep_from(xwtm_t *from, xwtm_t dur)
XWOS API:线程从一个时间起点睡眠到另一个时间点
Definition thd.h:879
函数调用图:

◆ freeze()

template<xwid_t TCpu = 0UL>
xwer_t xwos::SThd< TCpu >::freeze ( void  )
inlineprotected

冻结当前线程

在文件 SThd.hxx208 行定义.

209 {
210 return xwos_cthd_freeze();
211 }
static xwer_t xwos_cthd_freeze(void)
XWOS API:冻结当前线程
Definition thd.h:905
函数调用图:

◆ sThdMainFunction()

template<xwid_t TCpu = 0UL>
static xwer_t xwos::SThd< TCpu >::sThdMainFunction ( SThd< TCpu > *  thd)
inlinestaticprivate

在文件 SThd.hxx214 行定义.

214{ return thd->thdMainFunction(); }
函数调用图:
这是这个函数的调用关系图:

结构体成员变量说明

◆ mThdDesc

template<xwid_t TCpu = 0UL>
xwos_thd_d xwos::SThd< TCpu >::mThdDesc
private

线程描述符

在文件 SThd.hxx42 行定义.

◆ mThd

template<xwid_t TCpu = 0UL>
struct xwos_thd xwos::SThd< TCpu >::mThd
private

线程结构体

在文件 SThd.hxx43 行定义.


该类的文档由以下文件生成: