|
rtx的任务tcb中有ret_val和ret_upd这两个关键变量,前一个是储存系统调用返回值,后一个用于指示当本次系统调用将产生任务切换时,用于指示下次切换到本任务时,更新返回值,原因是再次切换回本任务时系统调用结果可能不同
系统调用函数中,当可能产生任务切换的情况时,一般都会更新ret_val值,用于表明函数返回值可能不可靠,最终的返回值应该从ret_val取得,到这里没有问题
很奇怪的是,某些明显会有任务切换的情形,竟然没有显式对ret_val赋值,这样的话返回值可能就会有问题呀???比如信号量发送函数
- /*--------------------------- rt_mbx_send -----------------------------------*/
- OS_RESULT rt_mbx_send (OS_ID mailbox, void *p_msg, U16 timeout) {
- /* Send message to a mailbox */
- P_MCB p_MCB = mailbox;
- P_TCB p_TCB;
- if (p_MCB->p_lnk != NULL && p_MCB->count == 0) {
- /* A task is waiting for message */
- p_TCB = rt_get_first ((P_XCB)p_MCB);
- *p_TCB->msg = p_msg;
- p_TCB->ret_val = OS_R_MBX;
- rt_rmv_dly (p_TCB);
- rt_dispatch (p_TCB);
- os_tsk.run->ret_val = OS_R_OK;
- }
- else {
- /* Store message in mailbox queue */
- if (p_MCB->count == p_MCB->size) {
- /* No free message entry, wait for one. If message queue is full, */
- /* then no task is waiting for message. The 'p_MCB->p_lnk' list */
- /* pointer can now be reused for send message waits task list. */
- if (timeout == 0) {
- return (OS_R_TMO);
- }
- if (p_MCB->p_lnk != NULL) {
- rt_put_prio ((P_XCB)p_MCB, os_tsk.run);
- }
- else {
- p_MCB->p_lnk = os_tsk.run;
- os_tsk.run->p_lnk = NULL;
- os_tsk.run->p_rlnk = (P_TCB)p_MCB;
- /* Signal the 'isr_mbx_receive ()' that the task is waiting */
- /* to send a message */
- p_MCB->isr_st = 1;
- }
- os_tsk.run->msg = p_msg;
- rt_block (timeout, WAIT_MBX); //这里为何没有对ret_val赋值
- return (OS_R_TMO);
- }
- /* Yes, there is a free entry in a mailbox. */
- p_MCB->msg[p_MCB->first] = p_msg;
- rt_inc (&p_MCB->count);
- if (++p_MCB->first == p_MCB->size) {
- p_MCB->first = 0;
- }
- }
- return (OS_R_OK);
- }
复制代码 |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|