vxWorks系统任务tJobTask的实现及使用
来源:互联网 发布:js 什么时候使用链表 编辑:程序博客网 时间:2024/06/06 01:44
前面说了tIsr以及tExcTask函数,这两个任务都是关于中断的,这里说的tJobTask是正常任务,跟中断没有关系。实现的就是简单的把一个函数延后执行。
/*记录job的结构体*/typedef struct { FUNCPTR func; /* job function */ int arg [JOB_MAX_ARGS]; /* args for function */ int clientTid; /* client task Id */ int clientPrio; /* client task Priority */ int * pResult; /* pointer to job result, supplied by client */#ifdef _WRS_CONFIG_SMP cpuset_t affinity;#endif } TASK_LEVEL_JOB;
/*job队列*/LOCAL TASK_LEVEL_JOB workerJob;
初始化过程:usrRoot--->usrIosExtraInit--->jobLibInit
/*初始化*/STATUS jobLibInit ( int jobTaskStackSize /* job task stack size */ ) {/*初始化clientMutex信号量*/ if (semMInit (&clientMutex, (SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE | SEM_INTERRUPTIBLE)) != OK)return (ERROR); /*初始化jobMutex信号量*/ if (semMInit (&jobMutex, (SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_INTERRUPTIBLE)) != OK)return (ERROR);/*初始化jobSyncSem信号量,用于同步任务*/ if (semBInit (&jobSyncSem, (SEM_Q_PRIORITY | SEM_INTERRUPTIBLE), SEM_EMPTY) != OK)return (ERROR); /*创建系统函数tJobTask*/ if ((jobTaskId = taskSpawn ("tJobTask",JOB_TASK_PRIORITY, JOB_TASK_OPTIONS,jobTaskStackSize, (FUNCPTR) jobTask,0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) == ERROR)return (ERROR);/*设定增加任务的函数的指针*/ _func_jobTaskWorkAdd = (FUNCPTR) jobTaskWorkAdd; jobLibTaskInstalled = TRUE; return (OK); }
/*增加任务到任务队列中*/LOCAL STATUS jobTaskWorkAdd ( FUNCPTR func, /* job function */ int arg1, /* job argument */ int arg2, /* job argument */ int arg3, /* job argument */ int arg4, /* job argument */ int arg5, /* job argument */ int arg6, /* job argument */ int * pResult /* pointer to job result, supplied by client */ ) { char text [100];/*如果在中断上下文中,就出错*/ if (INT_CONTEXT ()) {errnoSet (S_intLib_NOT_ISR_CALLABLE);return (ERROR); }/*没有初始化,也出错返回*/ if (!jobLibTaskInstalled) { errnoSet (EINVAL); return (ERROR); }/*获取信号clientMutex,也就是控制了一次只能添加一个任务进来*/ if (semTake (&clientMutex, WAIT_FOREVER) == ERROR) { return (ERROR); }/*这里的jobMutex信号*/ if (semTake (&jobMutex, WAIT_FOREVER) == ERROR) { semGive (&clientMutex); return (ERROR); }/*存储任务*/ workerJob.func = func; workerJob.arg[0] = arg1; workerJob.arg[1] = arg2; workerJob.arg[2] = arg3; workerJob.arg[3] = arg4; workerJob.arg[4] = arg5; workerJob.arg[5] = arg6; workerJob.pResult = pResult; workerJob.clientTid = (int) taskIdCurrent;/*设置当前任务的的优先级*/ taskPriorityGet ((int) taskIdCurrent, &workerJob.clientPrio);/*设置jobTask的优先级*/ taskPrioritySet ((int) jobTaskId, workerJob.clientPrio);#ifdef _WRS_CONFIG_SMP/*设置任务对应的affinity*/ if (taskCpuAffinityGet (0, &workerJob.affinity) == OK){if (!CPUSET_ISZERO(workerJob.affinity)) { if (taskCpuAffinityGet ((int) jobTaskId, &jobTaskAffinity) == OK){taskCpuAffinitySet ((int) jobTaskId, workerJob.affinity);} else{CPUSET_ZERO (workerJob.affinity);} }}#endif/*防止任务被删除*/ TASK_SAFE (); semGive (&jobMutex); if (semMTakeByProxy (&jobMutex, jobTaskId) != OK){ text[0] = '\0'; EDR_KERNEL_FATAL_INJECT (NULL, NULL, NULL, NULL, text);} semGive (&clientMutex); /* Allow subsequent jobAdd() calls to progress *//*告诉tJobTask有任务来了*/ semGive (&jobSyncSem); TASK_UNSAFE (); return (OK); }
/*系统任务函数*/LOCAL void jobTask (void) { int result;/*防止任务被删除*/ TASK_SAFE(); FOREVER{semTake (&jobSyncSem, WAIT_FOREVER);/*执行任务*/result = (*workerJob.func) (workerJob.arg[0], workerJob.arg[1], workerJob.arg[2], workerJob.arg[3], workerJob.arg[4], workerJob.arg[5]);errno = 0;taskPrioritySet ((int) taskIdCurrent, JOB_TASK_PRIORITY); #ifdef _WRS_CONFIG_SMPif (!CPUSET_ISZERO(workerJob.affinity)) { taskCpuAffinitySet ((int) jobTaskId, jobTaskAffinity); }#endif }/*允许处理下一个*/semGive (&jobMutex);} }
阅读全文
0 0
- vxWorks系统任务tJobTask的实现及使用
- vxWorks中系统任务tIsr的实现及使用
- VxWorks的系统任务
- VxWorks系统任务
- Vxworks系统学习----任务
- VxWorks操作系统指南(2.4) VxWorks系统任务
- VxWorks的任务状态
- Vxworks系统学习之一----任务
- Vxworks系统学习之一----任务
- VxWorks启动后系统自带的任务
- VxWorks下的任务监控方法及应用
- VxWorks下的任务监控方法及应用
- vxworks系统下列表的使用
- vxworks系统下列表的使用
- VxWorks下实时多任务程序的实现
- VxWorks下消息、信号量的使用和任务创建
- VxWorks下消息、信号量的使用和任务创建
- Vxworks任务间的通信
- 1999-逆序排列
- sorl 6.6.0 定时更新索引
- FZU 2150 Fire Game
- 去掉ueditor默认过滤转换机制
- AVR基础
- vxWorks系统任务tJobTask的实现及使用
- java线程池
- Flink 入门
- 【转载】Web移动端Fixed布局的解决方案
- trap or not 对于link 时产生的不同的错误信息
- String、StringBuffer与StringBuilder之间区别
- 初学者---简介java中的对象和类(2)
- [Git] 修改之前某次 commit 日志和内容
- 检测到在集成的托管管道模式下不适用的ASP.NET设置的解决方法(非简单设置为【经典】模式)。