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
146struct xwos_thd {
147 struct xwosdl_thd osthd;
148};
149
153typedef xwer_t (* xwos_thd_f)(void *);
154
158typedef struct {
159 struct xwos_thd * thd;
161} xwos_thd_d;
162
166#define XWOS_THD_NILD ((xwos_thd_d){NULL, 0,})
167
172 const char * name;
182 bool detached;
184};
185
198};
199
203#define __xwos_thd_stack __xwcc_alignl1cache
204
208#define XWOS_STACK_SIZE_DEFAULT XWMMCFG_STACK_SIZE_DEFAULT
209
213#define XWOS_STACK_SIZE_MIN XWMMCFG_STACK_SIZE_MIN
214
218#define XWOS_STACK_GUARD_SIZE_DEFAULT XWMMCFG_STACK_GUARD_SIZE_DEFAULT
219
223#define XWOS_THD_LOCAL_DATA_NUM XWOSDL_THD_LOCAL_DATA_NUM
224
231 void * arg;
232};
233
254{
255 xwosdl_thd_attr_init((struct xwosdl_thd_attr *)attr);
256}
257
295 const struct xwos_thd_attr * attr,
296 xwos_thd_f thdfunc, void * arg)
297{
298 return xwosdl_thd_init(&thd->osthd, (xwosdl_thd_d *)thdd,
299 (const struct xwosdl_thd_attr *)attr,
300 // cppcheck-suppress [misra-c2012-11.1]
301 (xwosdl_thd_f)thdfunc, arg);
302}
303
319{
320 return xwosdl_thd_grab(&thdd.thd->osthd);
321}
322
338{
339 return xwosdl_thd_put(&thdd.thd->osthd);
340}
341
367 const struct xwos_thd_attr * attr,
368 xwos_thd_f thdfunc, void * arg)
369{
370 return xwosdl_thd_create((xwosdl_thd_d *)thdd,
371 (const struct xwosdl_thd_attr *)attr,
372 // cppcheck-suppress [misra-c2012-11.1]
373 (xwosdl_thd_f)thdfunc, arg);
374}
375
388{
389 return xwosdl_thd_acquire(&thdd.thd->osthd, thdd.tik);
390}
391
404{
405 return xwosdl_thd_release(&thdd.thd->osthd, thdd.tik);
406}
407
422xwer_t xwos_thd_launch(xwos_thd_d thdd, xwos_thd_f thdfunc, void * arg)
423{
424 return xwosdl_thd_launch(&thdd.thd->osthd, thdd.tik,
425 // cppcheck-suppress [misra-c2012-11.1]
426 (xwosdl_thd_f)thdfunc, arg);
427}
428
429
443{
444 return xwosdl_thd_get_attr(&thdd.thd->osthd, thdd.tik,
445 (struct xwosdl_thd_attr *)attr);
446}
447
461{
462 xwer_t rc;
463 struct xwosdl_thd_stack_info info;
464
465 rc = xwosdl_thd_get_stack_info(&thdd.thd->osthd, thdd.tik, &info);
466 if ((XWOK == rc) && (stack)) {
467 stack->sp = info.sp;
468 stack->tls = (xwstk_t *)info.tls;
469 stack->base = info.base;
470 stack->size = info.size;
471 stack->guard_base = info.guard_base;
472 stack->guard_size = info.guard_size;
473 stack->line = info.line;
474 stack->usage = info.usage;
475 }
476 return rc;
477}
478
492{
493 return xwosdl_thd_get_stack_usage(&thdd.thd->osthd, thdd.tik, usage);
494}
495
512{
513 return xwosdl_thd_intr(&thdd.thd->osthd, thdd.tik);
514}
515
543{
544 return xwosdl_thd_quit(&thdd.thd->osthd, thdd.tik);
545}
546
578{
579 return xwosdl_thd_join(&thdd.thd->osthd, thdd.tik, trc);
580}
581
601{
602 return xwosdl_thd_stop(&thdd.thd->osthd, thdd.tik, trc);
603}
604
623{
624 return xwosdl_thd_detach(&thdd.thd->osthd, thdd.tik);
625}
626
645{
646 return xwosdl_thd_migrate(&thdd.thd->osthd, thdd.tik, dstcpu);
647}
648
657{
658 xwosdl_thd_d thdd;
659
660 thdd = xwosdl_cthd_self();
661 return (xwos_thd_d){(struct xwos_thd *)thdd.thd, thdd.tik};
662}
663
672{
673 // cppcheck-suppress [misra-c2012-17.7]
675}
676
685{
686 // cppcheck-suppress [misra-c2012-17.7]
688}
689
698{
699 xwsz_t usage;
700
701 // cppcheck-suppress [misra-c2012-17.7]
703 return usage;
704}
705
713{
714 xwosdl_cthd_yield();
715}
716
728{
729 xwosdl_cthd_exit(rc);
730}
731
742{
743 return xwosdl_cthd_shld_frz();
744}
745
768{
769 return xwosdl_cthd_shld_stop();
770}
771
805bool xwos_cthd_frz_shld_stop(bool * frozen)
806{
807 return xwosdl_cthd_frz_shld_stop(frozen);
808}
809
828{
829 return xwosdl_cthd_sleep_to(xwtm_ft(dur));
830}
831
851{
852 return xwosdl_cthd_sleep_to(to);
853}
854
880{
881 return xwosdl_cthd_sleep_from(from, dur);
882}
883
906{
907 return xwosdl_cthd_freeze();
908}
909
910#if (XWOS_THD_LOCAL_DATA_NUM > 0U)
925{
926 return xwosdl_thd_set_data(&thdd.thd->osthd, thdd.tik, pos, data);
927}
928
942xwer_t xwos_thd_get_data(xwos_thd_d thdd, xwsq_t pos, void ** databuf)
943{
944 return xwosdl_thd_get_data(&thdd.thd->osthd, thdd.tik, pos, databuf);
945}
946
960{
961 return xwosdl_cthd_set_data(pos, data);
962}
963
976xwer_t xwos_cthd_get_data(xwsq_t pos, void ** databuf)
977{
978 return xwosdl_cthd_get_data(pos, databuf);
979
980}
981#endif
982
987#endif /* xwos/osal/thd.h */
#define __xwos_inline_api
Definition compiler.h:179
#define XWOK
No error
Definition errno.h:182
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:850
static xwer_t xwos_thd_grab(xwos_thd_d thdd)
XWOS API:增加线程对象的引用计数
Definition thd.h:318
static xwer_t xwos_thd_release(xwos_thd_d thdd)
XWOS API:检查对象的标签并减少引用计数
Definition thd.h:403
static xwer_t xwos_cthd_get_data(xwsq_t pos, void **databuf)
XWOS API:获取当前线程的本地数据指针
Definition thd.h:976
static xwer_t xwos_thd_stop(xwos_thd_d thdd, xwer_t *trc)
XWOS API:终止线程并等待它退出,回收线程内存资源,并抛出线程的返回值
Definition thd.h:600
static bool xwos_cthd_shld_stop(void)
XWOS API:判断当前线程是否可以退出
Definition thd.h:767
static xwer_t xwos_thd_intr(xwos_thd_d thdd)
XWOS API:中断线程的阻塞态和睡眠态
Definition thd.h:511
static void xwos_cthd_get_stack_info(struct xwos_thd_stack_info *stack)
XWOS API:获取线程自身的栈信息
Definition thd.h:684
static void xwos_thd_attr_init(struct xwos_thd_attr *attr)
XWOS API:初始化线程属性结构体
Definition thd.h:253
static xwer_t xwos_thd_put(xwos_thd_d thdd)
XWOS API:减少线程对象的引用计数
Definition thd.h:337
static xwer_t xwos_cthd_sleep_from(xwtm_t *from, xwtm_t dur)
XWOS API:线程从一个时间起点睡眠到另一个时间点
Definition thd.h:879
static xwer_t xwos_thd_acquire(xwos_thd_d thdd)
XWOS API:检查线程对象的标签并增加引用计数
Definition thd.h:387
static xwer_t xwos_thd_set_data(xwos_thd_d thdd, xwsq_t pos, void *data)
XWOS API:设置线程的本地数据指针
Definition thd.h:924
static xwer_t xwos_cthd_freeze(void)
XWOS API:冻结当前线程
Definition thd.h:905
static xwer_t xwos_thd_get_stack_usage(xwos_thd_d thdd, xwsz_t *usage)
XWOS API:获取线程的栈用量信息
Definition thd.h:491
xwer_t(* xwos_thd_f)(void *)
XWOS API:线程函数指针类型
Definition thd.h:153
static xwer_t xwos_thd_get_stack_info(xwos_thd_d thdd, struct xwos_thd_stack_info *stack)
XWOS API:获取线程的栈信息
Definition thd.h:460
static bool xwos_cthd_shld_frz(void)
XWOS API:判断当前线程是否可被冻结
Definition thd.h:741
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
static void xwos_cthd_get_attr(struct xwos_thd_attr *attr)
XWOS API:获取线程自身的属性
Definition thd.h:671
static xwer_t xwos_thd_detach(xwos_thd_d thdd)
XWMP API:分离线程
Definition thd.h:622
static xwer_t xwos_thd_quit(xwos_thd_d thdd)
XWOS API:通知线程退出
Definition thd.h:542
static xwos_thd_d xwos_cthd_self(void)
XWOS API:获取当前线程的对象描述符
Definition thd.h:656
static void xwos_cthd_yield(void)
XWOS API:当前线程通知调度器重新调度
Definition thd.h:712
static void xwos_cthd_exit(xwer_t rc)
XWOS API:退出当前线程
Definition thd.h:727
static bool xwos_cthd_frz_shld_stop(bool *frozen)
XWOS API:判断当前线程是否可被冻结,如果是,就冻结线程, 之后再判断线程是否可以退出
Definition thd.h:805
static xwer_t xwos_thd_migrate(xwos_thd_d thdd, xwid_t dstcpu)
XWOS API:将线程迁移到目标CPU
Definition thd.h:644
static xwer_t xwos_cthd_sleep(xwtm_t dur)
XWOS API:当前线程睡眠一段时间
Definition thd.h:827
static xwer_t xwos_thd_get_attr(xwos_thd_d thdd, struct xwos_thd_attr *attr)
XWOS API:获取线程的属性
Definition thd.h:442
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
static xwer_t xwos_cthd_set_data(xwsq_t pos, void *data)
XWOS API:设置当前线程的本地数据指针
Definition thd.h:959
static xwer_t xwos_thd_join(xwos_thd_d thdd, xwer_t *trc)
XWOS API:等待线程结束,回收线程内存资源,抛出它的返回值
Definition thd.h:577
static xwer_t xwos_thd_launch(xwos_thd_d thdd, xwos_thd_f thdfunc, void *arg)
XWOS API:加载线程
Definition thd.h:422
static xwer_t xwos_thd_get_data(xwos_thd_d thdd, xwsq_t pos, void **databuf)
XWOS API:获取线程的本地数据指针
Definition thd.h:942
static xwsz_t xwos_cthd_get_stack_usage(void)
XWOS API:获取线程自身的栈用量信息
Definition thd.h:697
static xwtm_t xwtm_ft(xwtm_t dur)
XWOS API:获取当前CPU的未来 系统时间 点
Definition time.h:72
操作系统抽象层:线程接口描述
操作系统抽象层:调度器
XWOS API:线程属性
Definition thd.h:171
xwsz_t stack_guard_size
Definition thd.h:179
bool privileged
Definition thd.h:183
xwstk_t * stack
Definition thd.h:173
const char * name
Definition thd.h:172
xwpr_t priority
Definition thd.h:181
bool detached
Definition thd.h:182
xwsz_t stack_size
Definition thd.h:177
XWOS API:线程对象描述符
Definition thd.h:158
xwsq_t tik
Definition thd.h:160
struct xwos_thd * thd
Definition thd.h:159
XWOS API:线程描述
Definition thd.h:228
void * arg
Definition thd.h:231
struct xwos_thd_attr attr
Definition thd.h:229
xwos_thd_f func
Definition thd.h:230
XWOS API:线程栈信息
Definition thd.h:189
xwstk_t * guard_base
Definition thd.h:194
xwsz_t guard_size
Definition thd.h:195
xwstk_t * sp
Definition thd.h:190
xwstk_t * tls
Definition thd.h:191
xwstk_t * base
Definition thd.h:192
xwstk_t * line
Definition thd.h:196
XWOS API:线程对象
Definition thd.h:146
struct xwmp_thd osthd
Definition thd.h:147
操作系统抽象层:时间
XWOS的标准头文件