注意,这里事件和其他get函数的大差别是,函数多了一个get_option,它表示当前是同时申请多个事件还是多个事件中的一个事件,申请后是否需要进行clear置位等等,我们不妨看看具体细节,
(1)判断函数是否在中断中;
(2)判断get_option是否合法;
(3)判断是否存在可以获取的事件,and或者是or;
(4)如果事件可以获取,那么再判断是否需要置位操作,函数返回;
(5)判断是否愿意等待,否则返回;
(6)判断是否禁止调度,是则返回;
(7)将自己pend到等待队列中;
(8)调用公共调度函数转到其他线程继续运行;
(9)当前线程重新得到运行的机会,根据选项清除标志位,函数返回。
看完了事件的申请,下面可以看看事件的设置函数了
RAW_U16 raw_event_set(RAW_EVENT *event_ptr, RAW_U32 flags_to_set, RAW_U8 set_option)
{
LIST *iter;
LIST *event_head_ptr;
LIST *iter_temp;
struct RAW_TASK_OBJ *task_ptr;
RAW_U8 status;
RAW_U8 need_sche = 0;
RAW_SR_ALLOC();
#if (RAW_EVENT_FUNCTION_CHECK > 0)
if (event_ptr == 0) {
return RAW_NULL_OBJECT;
}
if ((set_option != RAW_AND) && (set_option != RAW_OR)) {
return RAW_NO_THIS_OPTION;
}
#endif
event_head_ptr = &event_ptr->common_block_obj.block_list;
status = RAW_FALSE;
RAW_CRITICAL_ENTER();
/*if the set_option is AND_MASK, it just clear the flags and will return immediately!*/
if (set_option & RAW_FLAGS_AND_MASK) {
event_ptr->flags &= flags_to_set;
RAW_CRITICAL_EXIT();
return RAW_SUCCESS;
}
/*if it is or mask then set the flag and continue.........*/
else {
event_ptr->flags |= flags_to_set;
}
iter = event_head_ptr->next;
/*if list is not empty*/
while (iter !=event_head_ptr) {
task_ptr = list_entry(iter, RAW_TASK_OBJ, task_list);
iter_temp = iter->next;
if (task_ptr->raw_suspend_option & RAW_FLAGS_AND_MASK) {
if ((event_ptr->flags & task_ptr ->raw_suspend_flags) == task_ptr ->raw_suspend_flags)
status = RAW_TRUE;
else
status = RAW_FALSE;
}
else {
if (event_ptr->flags & task_ptr ->raw_suspend_flags)
status = RAW_TRUE;
else
status = RAW_FALSE;
}
if (status) {
/*Ok the task condition is met, just wake this task*/
raw_wake_object(task_ptr);
/*if task is waken up*/
need_sche = 1;
}
iter = iter_temp;
}
RAW_CRITICAL_EXIT();
if (need_sche) {
raw_sched();
}
return RAW_SUCCESS;
}
|