XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
thd.h
浏览该文件的文档.
1
13#ifndef __xwos_osal_thd_h__
14#define __xwos_osal_thd_h__
15
16#include <xwos/standard.h>
17#include <xwos/osal/jack/thd.h>
18#include <xwos/osal/time.h>
19#include <xwos/osal/skd.h>
20
137struct xwos_thd {
138 struct xwosdl_thd osthd;
139};
140
144typedef xwer_t (* xwos_thd_f)(void *);
145
149typedef struct {
150 struct xwos_thd * thd;
152} xwos_thd_d;
153
157#define XWOS_THD_NILD ((xwos_thd_d){NULL, 0,})
158
163 const char * name;
173 bool detached;
175};
176
180#define XWOS_STACK_SIZE_DEFAULT XWMMCFG_STACK_SIZE_DEFAULT
181
185#define XWOS_STACK_SIZE_MIN XWMMCFG_STACK_SIZE_MIN
186
190#define XWOS_STACK_GUARD_SIZE_DEFAULT XWMMCFG_STACK_GUARD_SIZE_DEFAULT
191
195#define XWOS_THD_LOCAL_DATA_NUM XWOSDL_THD_LOCAL_DATA_NUM
196
203 void * arg;
204};
205
226{
227 xwosdl_thd_attr_init((struct xwosdl_thd_attr *)attr);
228}
229
264 const struct xwos_thd_attr * attr,
265 xwos_thd_f thdfunc, void * arg)
266{
267 return xwosdl_thd_init(&thd->osthd, (xwosdl_thd_d *)thdd,
268 (const struct xwosdl_thd_attr *)attr,
269 // cppcheck-suppress [misra-c2012-11.1]
270 (xwosdl_thd_f)thdfunc, arg);
271}
272
288{
289 return xwosdl_thd_grab(&thdd.thd->osthd);
290}
291
307{
308 return xwosdl_thd_put(&thdd.thd->osthd);
309}
310
332 const struct xwos_thd_attr * attr,
333 xwos_thd_f thdfunc, void * arg)
334{
335 return xwosdl_thd_create((xwosdl_thd_d *)thdd,
336 (const struct xwosdl_thd_attr *)attr,
337 // cppcheck-suppress [misra-c2012-11.1]
338 (xwosdl_thd_f)thdfunc, arg);
339}
340
353{
354 return xwosdl_thd_acquire(&thdd.thd->osthd, thdd.tik);
355}
356
369{
370 return xwosdl_thd_release(&thdd.thd->osthd, thdd.tik);
371}
372
386{
387 return xwosdl_thd_get_attr(&thdd.thd->osthd, thdd.tik,
388 (struct xwosdl_thd_attr *)attr);
389}
390
407{
408 return xwosdl_thd_intr(&thdd.thd->osthd, thdd.tik);
409}
410
438{
439 return xwosdl_thd_quit(&thdd.thd->osthd, thdd.tik);
440}
441
473{
474 return xwosdl_thd_join(&thdd.thd->osthd, thdd.tik, trc);
475}
476
496{
497 return xwosdl_thd_stop(&thdd.thd->osthd, thdd.tik, trc);
498}
499
518{
519 return xwosdl_thd_detach(&thdd.thd->osthd, thdd.tik);
520}
521
540{
541 return xwosdl_thd_migrate(&thdd.thd->osthd, thdd.tik, dstcpu);
542}
543
552{
553 xwosdl_thd_d thdd;
554
555 thdd = xwosdl_cthd_self();
556 return (xwos_thd_d){(struct xwos_thd *)thdd.thd, thdd.tik};
557}
558
567{
568 // cppcheck-suppress [misra-c2012-17.7]
570}
571
579{
580 xwosdl_cthd_yield();
581}
582
594{
595 xwosdl_cthd_exit(rc);
596}
597
608{
609 return xwosdl_cthd_shld_frz();
610}
611
634{
635 return xwosdl_cthd_shld_stop();
636}
637
671bool xwos_cthd_frz_shld_stop(bool * frozen)
672{
673 return xwosdl_cthd_frz_shld_stop(frozen);
674}
675
694{
695 return xwosdl_cthd_sleep_to(xwtm_ft(dur));
696}
697
717{
718 return xwosdl_cthd_sleep_to(to);
719}
720
746{
747 return xwosdl_cthd_sleep_from(from, dur);
748}
749
772{
773 return xwosdl_cthd_freeze();
774}
775
776#if (XWOS_THD_LOCAL_DATA_NUM > 0U)
791{
792 return xwosdl_thd_set_data(&thdd.thd->osthd, thdd.tik, pos, data);
793}
794
808xwer_t xwos_thd_get_data(xwos_thd_d thdd, xwsq_t pos, void ** databuf)
809{
810 return xwosdl_thd_get_data(&thdd.thd->osthd, thdd.tik, pos, databuf);
811}
812
826{
827 return xwosdl_cthd_set_data(pos, data);
828}
829
842xwer_t xwos_cthd_get_data(xwsq_t pos, void ** databuf)
843{
844 return xwosdl_cthd_get_data(pos, databuf);
845
846}
847#endif
848
853#endif /* xwos/osal/thd.h */
#define __xwos_inline_api
Definition compiler.h:179
xws64_t xwtm_t
XWOS系统时间 (有符号)
Definition type.h:742
signed long xwer_t
Definition type.h:554
unsigned long xwid_t
Definition type.h:481
xws32_t xwpr_t
Definition type.h:534
xwptr_t xwstk_t
Definition type.h:392
unsigned long xwsz_t
Definition type.h:339
unsigned long xwsq_t
Definition type.h:445
static xwer_t xwos_cthd_sleep_to(xwtm_t to)
XWOS API:线程睡眠到一个时间点
Definition thd.h:716
static xwer_t xwos_thd_grab(xwos_thd_d thdd)
XWOS API:增加线程对象的引用计数
Definition thd.h:287
static xwer_t xwos_thd_release(xwos_thd_d thdd)
XWOS API:检查对象的标签并减少引用计数
Definition thd.h:368
static xwer_t xwos_cthd_get_data(xwsq_t pos, void **databuf)
XWOS API:获取当前线程的本地数据指针
Definition thd.h:842
static xwer_t xwos_thd_stop(xwos_thd_d thdd, xwer_t *trc)
XWOS API:终止线程并等待它退出,回收线程内存资源,并抛出线程的返回值
Definition thd.h:495
static bool xwos_cthd_shld_stop(void)
XWOS API:判断当前线程是否可以退出
Definition thd.h:633
static xwer_t xwos_thd_intr(xwos_thd_d thdd)
XWOS API:中断线程的阻塞态和睡眠态
Definition thd.h:406
static void xwos_thd_attr_init(struct xwos_thd_attr *attr)
XWOS API:初始化线程属性结构体
Definition thd.h:225
static xwer_t xwos_thd_put(xwos_thd_d thdd)
XWOS API:减少线程对象的引用计数
Definition thd.h:306
static xwer_t xwos_cthd_sleep_from(xwtm_t *from, xwtm_t dur)
XWOS API:线程从一个时间起点睡眠到另一个时间点
Definition thd.h:745
static xwer_t xwos_thd_acquire(xwos_thd_d thdd)
XWOS API:检查线程对象的标签并增加引用计数
Definition thd.h:352
static xwer_t xwos_thd_set_data(xwos_thd_d thdd, xwsq_t pos, void *data)
XWOS API:设置线程的本地数据指针
Definition thd.h:790
static xwer_t xwos_cthd_freeze(void)
XWOS API:冻结当前线程
Definition thd.h:771
xwer_t(* xwos_thd_f)(void *)
XWOS API:线程函数指针类型
Definition thd.h:144
static bool xwos_cthd_shld_frz(void)
XWOS API:判断当前线程是否可被冻结
Definition thd.h:607
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:331
static void xwos_cthd_get_attr(struct xwos_thd_attr *attr)
XWOS API:获取线程自身的属性
Definition thd.h:566
static xwer_t xwos_thd_detach(xwos_thd_d thdd)
XWMP API:分离线程
Definition thd.h:517
static xwer_t xwos_thd_quit(xwos_thd_d thdd)
XWOS API:通知线程退出
Definition thd.h:437
static xwos_thd_d xwos_cthd_self(void)
XWOS API:获取当前线程的对象描述符
Definition thd.h:551
static void xwos_cthd_yield(void)
XWOS API:当前线程通知调度器重新调度
Definition thd.h:578
static void xwos_cthd_exit(xwer_t rc)
XWOS API:退出当前线程
Definition thd.h:593
static bool xwos_cthd_frz_shld_stop(bool *frozen)
XWOS API:判断当前线程是否可被冻结,如果是,就冻结线程, 之后再判断线程是否可以退出
Definition thd.h:671
static xwer_t xwos_thd_migrate(xwos_thd_d thdd, xwid_t dstcpu)
XWOS API:将线程迁移到目标CPU
Definition thd.h:539
static xwer_t xwos_cthd_sleep(xwtm_t dur)
XWOS API:线程睡眠一段时间
Definition thd.h:693
static xwer_t xwos_thd_get_attr(xwos_thd_d thdd, struct xwos_thd_attr *attr)
XWOS API:获取线程的属性
Definition thd.h:385
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:263
static xwer_t xwos_cthd_set_data(xwsq_t pos, void *data)
XWOS API:设置当前线程的本地数据指针
Definition thd.h:825
static xwer_t xwos_thd_join(xwos_thd_d thdd, xwer_t *trc)
XWOS API:等待线程结束,回收线程内存资源,抛出它的返回值
Definition thd.h:472
static xwer_t xwos_thd_get_data(xwos_thd_d thdd, xwsq_t pos, void **databuf)
XWOS API:获取线程的本地数据指针
Definition thd.h:808
static xwtm_t xwtm_ft(xwtm_t dur)
XWOS API:获取当前CPU的未来 系统时间 点
Definition time.h:72
操作系统抽象层:线程接口描述
操作系统抽象层:调度器
XWOS API:线程属性
Definition thd.h:162
xwsz_t stack_guard_size
Definition thd.h:170
bool privileged
Definition thd.h:174
xwstk_t * stack
Definition thd.h:164
const char * name
Definition thd.h:163
xwpr_t priority
Definition thd.h:172
bool detached
Definition thd.h:173
xwsz_t stack_size
Definition thd.h:168
XWOS API:线程对象描述符
Definition thd.h:149
xwsq_t tik
Definition thd.h:151
struct xwos_thd * thd
Definition thd.h:150
XWOS API:线程描述
Definition thd.h:200
void * arg
Definition thd.h:203
struct xwos_thd_attr attr
Definition thd.h:201
xwos_thd_f func
Definition thd.h:202
XWOS API:线程对象
Definition thd.h:137
struct xwmp_thd osthd
Definition thd.h:138
操作系统抽象层:时间
XWOS的标准头文件