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

动态线程 更多...

#include <DThd.hxx>

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

Public 成员函数

 DThd (const char *name, 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 ~DThd ()
 动态线程析构函数
 
void launch ()
 加载线程
 
xwer_t getDThdCtorRc ()
 获取动态线程构造的结果
 
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 acquire ()
 
xwer_t release ()
 

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 (DThd *thd)
 

Private 属性

xwos_thd_d mThdDesc
 
xwer_t mCtorRc
 

详细描述

template<xwid_t TCpu = 0>
class xwos::DThd< TCpu >

动态线程

参数
[in]TCpu目标CPU

在文件 DThd.hxx35 行定义.

构造及析构函数说明

◆ DThd()

template<xwid_t TCpu = 0>
xwos::DThd< TCpu >::DThd ( const char *  name,
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_size线程栈的大小
[in]stack_guard_size栈内存警戒线位置
[in]priority优先级
[in]detached是否为分离态
[in]privileged是否为特权线程

在文件 DThd.hxx51 行定义.

55 : mThdDesc{ nullptr, 0 }
56 {
57 struct xwos_thd_attr attr({
58 .name = name,
59 .stack = (xwstk_t *)NULL,
60 .stack_size = stack_size,
61 .stack_guard_size = stack_guard_size,
62 .priority = priority,
63 .detached = detached,
64 .privileged = privileged,
65 });
66 mCtorRc = xwos_thd_create(&mThdDesc, &attr, nullptr, nullptr);
67 }
xwos_thd_d mThdDesc
Definition DThd.hxx:38
xwer_t mCtorRc
Definition DThd.hxx:39
#define NULL
Definition type.h:28
xwptr_t xwstk_t
Definition type.h:392
static xwer_t xwos_thd_create(xwos_thd_d *thdd, const struct xwos_thd_attr *attr, xwos_thd_f thdfunc, void *arg)
XWOS API:使用动态申请内存方式创建线程并初始化
Definition thd.h:366
XWOS API:线程属性
Definition thd.h:171
函数调用图:

◆ ~DThd()

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

动态线程析构函数

在文件 DThd.hxx71 行定义.

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

成员函数说明

◆ launch()

template<xwid_t TCpu = 0>
void xwos::DThd< TCpu >::launch ( )
inline

加载线程

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

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

在文件 DThd.hxx82 行定义.

83 {
84 xwer_t rc;
85
86 if (TCpu == Cpu::getLocalCpuId()) {
88 } else {
89 rc = -EHOSTUNREACH;
90 }
91 return rc;
92 }
static xwid_t getLocalCpuId()
获取当前CPU的ID
Definition Cpu.hxx:64
static xwer_t sThdMainFunction(DThd *thd)
Definition DThd.hxx:215
#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
函数调用图:

◆ getDThdCtorRc()

template<xwid_t TCpu = 0>
xwer_t xwos::DThd< TCpu >::getDThdCtorRc ( )
inline

获取动态线程构造的结果

注解
动态对象的创建可能会因为内存不足构造失败。

在文件 DThd.hxx98 行定义.

98{ return mCtorRc; }

◆ getStackInfo()

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

获取当前线程的栈信息

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

在文件 DThd.hxx103 行定义.

104 {
105 return xwos_thd_get_stack_info(mThdDesc, stack);
106 }
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 = 0>
xwer_t xwos::DThd< TCpu >::intr ( )
inline

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

在文件 DThd.hxx110 行定义.

110{ 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 = 0>
xwer_t xwos::DThd< TCpu >::quit ( )
inline

通知线程退出

在文件 DThd.hxx114 行定义.

114{ 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 = 0>
xwer_t xwos::DThd< TCpu >::join ( xwer_t trc)
inline

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

在文件 DThd.hxx118 行定义.

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

◆ stop()

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

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

在文件 DThd.hxx125 行定义.

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

◆ detach()

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

终止线程并等待它退出

在文件 DThd.hxx132 行定义.

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

◆ getXwosObj()

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

获取XWOS对象指针

在文件 DThd.hxx136 行定义.

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

◆ acquire()

template<xwid_t TCpu = 0>
xwer_t xwos::DThd< TCpu >::acquire ( )
inline

增加引用计数

在文件 DThd.hxx139 行定义.

函数调用图:

◆ release()

template<xwid_t TCpu = 0>
xwer_t xwos::DThd< TCpu >::release ( )
inline

减少引用计数

在文件 DThd.hxx140 行定义.

函数调用图:

◆ thdMainFunction()

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

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

在文件 DThd.hxx147 行定义.

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

◆ yield()

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

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

在文件 DThd.hxx153 行定义.

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

◆ exit()

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

退出当前线程

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

在文件 DThd.hxx161 行定义.

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

◆ shouldFreeze()

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

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

在文件 DThd.hxx168 行定义.

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

◆ shouldStop()

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

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

在文件 DThd.hxx175 行定义.

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

◆ sleep()

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

当前线程睡眠一段时间

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

在文件 DThd.hxx183 行定义.

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

◆ sleepTo()

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

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

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

在文件 DThd.hxx191 行定义.

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

◆ sleepFrom()

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

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

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

在文件 DThd.hxx202 行定义.

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

◆ freeze()

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

冻结当前线程

在文件 DThd.hxx209 行定义.

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

◆ sThdMainFunction()

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

在文件 DThd.hxx215 行定义.

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

结构体成员变量说明

◆ mThdDesc

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

线程描述符

在文件 DThd.hxx38 行定义.

◆ mCtorRc

template<xwid_t TCpu = 0>
xwer_t xwos::DThd< TCpu >::mCtorRc
private

线程构造的结果

在文件 DThd.hxx39 行定义.


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