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
144struct xwos_thd {
145 struct xwosdl_thd osthd;
146};
147
151typedef xwer_t (* xwos_thd_f)(void *);
152
156typedef struct {
157 struct xwos_thd * thd;
159} xwos_thd_d;
160
164#define XWOS_THD_NILD ((xwos_thd_d){NULL, 0,})
165
170 const char * name;
180 bool detached;
182};
183
194};
195
199#define XWOS_STACK_SIZE_DEFAULT XWMMCFG_STACK_SIZE_DEFAULT
200
204#define XWOS_STACK_SIZE_MIN XWMMCFG_STACK_SIZE_MIN
205
209#define XWOS_STACK_GUARD_SIZE_DEFAULT XWMMCFG_STACK_GUARD_SIZE_DEFAULT
210
214#define XWOS_THD_LOCAL_DATA_NUM XWOSDL_THD_LOCAL_DATA_NUM
215
222 void * arg;
223};
224
245{
246 xwosdl_thd_attr_init((struct xwosdl_thd_attr *)attr);
247}
248
283 const struct xwos_thd_attr * attr,
284 xwos_thd_f thdfunc, void * arg)
285{
286 return xwosdl_thd_init(&thd->osthd, (xwosdl_thd_d *)thdd,
287 (const struct xwosdl_thd_attr *)attr,
288 // cppcheck-suppress [misra-c2012-11.1]
289 (xwosdl_thd_f)thdfunc, arg);
290}
291
307{
308 return xwosdl_thd_grab(&thdd.thd->osthd);
309}
310
326{
327 return xwosdl_thd_put(&thdd.thd->osthd);
328}
329
351 const struct xwos_thd_attr * attr,
352 xwos_thd_f thdfunc, void * arg)
353{
354 return xwosdl_thd_create((xwosdl_thd_d *)thdd,
355 (const struct xwosdl_thd_attr *)attr,
356 // cppcheck-suppress [misra-c2012-11.1]
357 (xwosdl_thd_f)thdfunc, arg);
358}
359
372{
373 return xwosdl_thd_acquire(&thdd.thd->osthd, thdd.tik);
374}
375
388{
389 return xwosdl_thd_release(&thdd.thd->osthd, thdd.tik);
390}
391
405{
406 return xwosdl_thd_get_attr(&thdd.thd->osthd, thdd.tik,
407 (struct xwosdl_thd_attr *)attr);
408}
409
423{
424 xwer_t rc;
425 struct xwosdl_thd_stack_info info;
426
427 rc = xwosdl_thd_get_stack_info(&thdd.thd->osthd, thdd.tik, &info);
428 if ((XWOK == rc) && (stack)) {
429 stack->sp = info.sp;
430 stack->tls = (xwstk_t *)info.tls;
431 stack->base = info.base;
432 stack->size = info.size;
433 stack->guard_base = info.guard_base;
434 stack->guard_size = info.guard_size;
435 }
436 return rc;
437}
438
455{
456 return xwosdl_thd_intr(&thdd.thd->osthd, thdd.tik);
457}
458
486{
487 return xwosdl_thd_quit(&thdd.thd->osthd, thdd.tik);
488}
489
521{
522 return xwosdl_thd_join(&thdd.thd->osthd, thdd.tik, trc);
523}
524
544{
545 return xwosdl_thd_stop(&thdd.thd->osthd, thdd.tik, trc);
546}
547
566{
567 return xwosdl_thd_detach(&thdd.thd->osthd, thdd.tik);
568}
569
588{
589 return xwosdl_thd_migrate(&thdd.thd->osthd, thdd.tik, dstcpu);
590}
591
600{
601 xwosdl_thd_d thdd;
602
603 thdd = xwosdl_cthd_self();
604 return (xwos_thd_d){(struct xwos_thd *)thdd.thd, thdd.tik};
605}
606
615{
616 // cppcheck-suppress [misra-c2012-17.7]
618}
619
628{
629 // cppcheck-suppress [misra-c2012-17.7]
631}
632
640{
641 xwosdl_cthd_yield();
642}
643
655{
656 xwosdl_cthd_exit(rc);
657}
658
669{
670 return xwosdl_cthd_shld_frz();
671}
672
695{
696 return xwosdl_cthd_shld_stop();
697}
698
732bool xwos_cthd_frz_shld_stop(bool * frozen)
733{
734 return xwosdl_cthd_frz_shld_stop(frozen);
735}
736
755{
756 return xwosdl_cthd_sleep_to(xwtm_ft(dur));
757}
758
778{
779 return xwosdl_cthd_sleep_to(to);
780}
781
807{
808 return xwosdl_cthd_sleep_from(from, dur);
809}
810
833{
834 return xwosdl_cthd_freeze();
835}
836
837#if (XWOS_THD_LOCAL_DATA_NUM > 0U)
852{
853 return xwosdl_thd_set_data(&thdd.thd->osthd, thdd.tik, pos, data);
854}
855
869xwer_t xwos_thd_get_data(xwos_thd_d thdd, xwsq_t pos, void ** databuf)
870{
871 return xwosdl_thd_get_data(&thdd.thd->osthd, thdd.tik, pos, databuf);
872}
873
887{
888 return xwosdl_cthd_set_data(pos, data);
889}
890
903xwer_t xwos_cthd_get_data(xwsq_t pos, void ** databuf)
904{
905 return xwosdl_cthd_get_data(pos, databuf);
906
907}
908#endif
909
914#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:777
static xwer_t xwos_thd_grab(xwos_thd_d thdd)
XWOS API:增加线程对象的引用计数
Definition thd.h:306
static xwer_t xwos_thd_release(xwos_thd_d thdd)
XWOS API:检查对象的标签并减少引用计数
Definition thd.h:387
static xwer_t xwos_cthd_get_data(xwsq_t pos, void **databuf)
XWOS API:获取当前线程的本地数据指针
Definition thd.h:903
static xwer_t xwos_thd_stop(xwos_thd_d thdd, xwer_t *trc)
XWOS API:终止线程并等待它退出,回收线程内存资源,并抛出线程的返回值
Definition thd.h:543
static bool xwos_cthd_shld_stop(void)
XWOS API:判断当前线程是否可以退出
Definition thd.h:694
static xwer_t xwos_thd_intr(xwos_thd_d thdd)
XWOS API:中断线程的阻塞态和睡眠态
Definition thd.h:454
static void xwos_cthd_get_stack_info(struct xwos_thd_stack_info *stack)
XWOS API:获取线程自身的栈信息
Definition thd.h:627
static void xwos_thd_attr_init(struct xwos_thd_attr *attr)
XWOS API:初始化线程属性结构体
Definition thd.h:244
static xwer_t xwos_thd_put(xwos_thd_d thdd)
XWOS API:减少线程对象的引用计数
Definition thd.h:325
static xwer_t xwos_cthd_sleep_from(xwtm_t *from, xwtm_t dur)
XWOS API:线程从一个时间起点睡眠到另一个时间点
Definition thd.h:806
static xwer_t xwos_thd_acquire(xwos_thd_d thdd)
XWOS API:检查线程对象的标签并增加引用计数
Definition thd.h:371
static xwer_t xwos_thd_set_data(xwos_thd_d thdd, xwsq_t pos, void *data)
XWOS API:设置线程的本地数据指针
Definition thd.h:851
static xwer_t xwos_cthd_freeze(void)
XWOS API:冻结当前线程
Definition thd.h:832
xwer_t(* xwos_thd_f)(void *)
XWOS API:线程函数指针类型
Definition thd.h:151
static xwer_t xwos_thd_get_stack_info(xwos_thd_d thdd, struct xwos_thd_stack_info *stack)
XWOS API:获取线程的栈信息
Definition thd.h:422
static bool xwos_cthd_shld_frz(void)
XWOS API:判断当前线程是否可被冻结
Definition thd.h:668
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:350
static void xwos_cthd_get_attr(struct xwos_thd_attr *attr)
XWOS API:获取线程自身的属性
Definition thd.h:614
static xwer_t xwos_thd_detach(xwos_thd_d thdd)
XWMP API:分离线程
Definition thd.h:565
static xwer_t xwos_thd_quit(xwos_thd_d thdd)
XWOS API:通知线程退出
Definition thd.h:485
static xwos_thd_d xwos_cthd_self(void)
XWOS API:获取当前线程的对象描述符
Definition thd.h:599
static void xwos_cthd_yield(void)
XWOS API:当前线程通知调度器重新调度
Definition thd.h:639
static void xwos_cthd_exit(xwer_t rc)
XWOS API:退出当前线程
Definition thd.h:654
static bool xwos_cthd_frz_shld_stop(bool *frozen)
XWOS API:判断当前线程是否可被冻结,如果是,就冻结线程, 之后再判断线程是否可以退出
Definition thd.h:732
static xwer_t xwos_thd_migrate(xwos_thd_d thdd, xwid_t dstcpu)
XWOS API:将线程迁移到目标CPU
Definition thd.h:587
static xwer_t xwos_cthd_sleep(xwtm_t dur)
XWOS API:当前线程睡眠一段时间
Definition thd.h:754
static xwer_t xwos_thd_get_attr(xwos_thd_d thdd, struct xwos_thd_attr *attr)
XWOS API:获取线程的属性
Definition thd.h:404
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:282
static xwer_t xwos_cthd_set_data(xwsq_t pos, void *data)
XWOS API:设置当前线程的本地数据指针
Definition thd.h:886
static xwer_t xwos_thd_join(xwos_thd_d thdd, xwer_t *trc)
XWOS API:等待线程结束,回收线程内存资源,抛出它的返回值
Definition thd.h:520
static xwer_t xwos_thd_get_data(xwos_thd_d thdd, xwsq_t pos, void **databuf)
XWOS API:获取线程的本地数据指针
Definition thd.h:869
static xwtm_t xwtm_ft(xwtm_t dur)
XWOS API:获取当前CPU的未来 系统时间 点
Definition time.h:72
操作系统抽象层:线程接口描述
操作系统抽象层:调度器
XWOS API:线程属性
Definition thd.h:169
xwsz_t stack_guard_size
Definition thd.h:177
bool privileged
Definition thd.h:181
xwstk_t * stack
Definition thd.h:171
const char * name
Definition thd.h:170
xwpr_t priority
Definition thd.h:179
bool detached
Definition thd.h:180
xwsz_t stack_size
Definition thd.h:175
XWOS API:线程对象描述符
Definition thd.h:156
xwsq_t tik
Definition thd.h:158
struct xwos_thd * thd
Definition thd.h:157
XWOS API:线程描述
Definition thd.h:219
void * arg
Definition thd.h:222
struct xwos_thd_attr attr
Definition thd.h:220
xwos_thd_f func
Definition thd.h:221
XWOS API:线程栈信息
Definition thd.h:187
xwstk_t * guard_base
Definition thd.h:192
xwsz_t guard_size
Definition thd.h:193
xwstk_t * sp
Definition thd.h:188
xwstk_t * tls
Definition thd.h:189
xwstk_t * base
Definition thd.h:190
XWOS API:线程对象
Definition thd.h:144
struct xwmp_thd osthd
Definition thd.h:145
操作系统抽象层:时间
XWOS的标准头文件