Nucleus event函数分析

在Nucleus的等待事件函数EVC_Retrieve_Events中有这么一段函数

  1. if (suspend)  
  2. {  
  3.   
  4. /* Suspension is selected.  */  
  5.   
  6. /* Increment the number of tasks waiting.  */  
  7. event_group -> ev_tasks_waiting++;  
  8.   
  9. /* Setup the suspend block and suspend the calling task.  */  
  10. suspend_ptr =  &suspend_block;  
  11. suspend_ptr -> ev_event_group =              event_group;  
  12. suspend_ptr -> ev_suspend_link.cs_next =     NU_NULL;  
  13. suspend_ptr -> ev_suspend_link.cs_previous = NU_NULL;  
  14. task =                            (TC_TCB *) TCT_Current_Thread();  
  15. suspend_ptr -> ev_suspended_task =           task;  
  16. suspend_ptr -> ev_requested_events =         requested_events;  
  17. suspend_ptr -> ev_operation =                operation;  
  18.   
  19. /* Link the suspend block into the list of suspended tasks on this 
  20. event group.  */  
  21. CSC_Place_On_List((CS_NODE **)  
  22. &(event_group -> ev_suspension_list),  
  23. &(suspend_ptr -> ev_suspend_link));  
  24.   
  25. /* Finally, suspend the calling task. Note that the suspension call 
  26. automatically clears the protection on the event group.  */  
  27. TCC_Suspend_Task((NU_TASK *) task, NU_EVENT_SUSPEND,  
  28. EVC_Cleanup, suspend_ptr, suspend);  
  29.   
  30. /* Pickup the return status and the actual retrieved events.  */  
  31. status =             suspend_ptr -> ev_return_status;  
  32. *retrieved_events =  suspend_ptr -> ev_actual_events;  
  33.   
  34. }  
  35. else  
  36. ..........  

我们看到当task因为该事件而阻塞的代码

  1. /* Finally, suspend the calling task. Note that the suspension call 
  2. automatically clears the protection on the event group.  */  
  3. TCC_Suspend_Task((NU_TASK *) task, NU_EVENT_SUSPEND,  
  4. EVC_Cleanup, suspend_ptr, suspend);  

执行后紧接着的就是将等待事件的状态和接受到消息的变量进行了赋值,这是为什么呢,这样正确吗?
原来是这样的。当TCC_Suspend_Task被调用后当前task被挂起,这个函数以后的代码已经不会再接着执行了。等到这个task恢复时说明这个事件已经等到了,这个事件的值是在EVC_Set_Events函数中被设置的。

  1. if (compare)  
  2. {  
  3.   
  4. /* Decrement the number of tasks waiting counter.  */  
  5. event_group -> ev_tasks_waiting--;  
  6.   
  7. /* Determine if consumption is requested.  */  
  8. if (suspend_ptr -> ev_operation & EV_CONSUME)  
  9.   
  10. /* Keep track of the event flags to consume.  */  
  11. consume =  consume | suspend_ptr -> ev_requested_events;  
  12.   
  13. /* Remove the first suspended block from the list.  */  
  14. CSC_Remove_From_List((CS_NODE **)  
  15. &(event_group -> ev_suspension_list),  
  16. &(suspend_ptr -> ev_suspend_link));  
  17.   
  18. /* Setup the appropriate return value.  */  
  19. suspend_ptr -> ev_return_status =  NU_SUCCESS;  
  20. suspend_ptr -> ev_actual_events =  
  21. event_group -> ev_current_events;  
  22.   
  23. /* Resume the suspended task.  */  
  24. preempt = preempt |  
  25. TCC_Resume_Task((NU_TASK *) suspend_ptr -> ev_suspended_task,  
  26. NU_EVENT_SUSPEND);  
  27.   
  28. }  

可以看到设置的返回值就是EVC_Retrieve_Events函数中的返回值。

Nucleus event函数分析

Nucleus event函数分析

Nucleus event函数分析

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值