📄 evc.c
字号:
/* Call stack checking function to check for an overflow condition. */ TCT_Check_Stack();#endif#ifdef NU_ENABLE_HISTORY /* Make an entry that corresponds to this function in the system history log. */ HIC_Make_History_Entry(NU_DELETE_EVENT_GROUP_ID, (UNSIGNED) event_group, (UNSIGNED) 0, (UNSIGNED) 0);#endif /* Protect against simultaneous access to the event group. */ TCT_System_Protect();#ifdef INCLUDE_PROVIEW _RTProf_DumpEventGroup(RT_PROF_DELETE_EVENT_GROUP, event_group, RT_PROF_OK);#endif /*INCLUDE_PROVIEW*/ /* Clear the event group ID. */ event_group -> ev_id = 0; /* Release protection. */ TCT_Unprotect(); /* Protect against access to the list of created event groups. */ TCT_Protect(&EVD_List_Protect); /* Remove the event_group from the list of created event groups. */ CSC_Remove_From_List(&EVD_Created_Event_Groups_List, &(event_group -> ev_created)); /* Decrement the total number of created event groups. */ EVD_Total_Event_Groups--; /* Pickup the suspended task pointer list. */ suspend_ptr = event_group -> ev_suspension_list; /* Walk the chain task(s) currently suspended on the event_group. */ preempt = 0; while (suspend_ptr) { /* Protect against system access. */ TCT_System_Protect(); /* Resume the suspended task. Insure that the status returned is NU_GROUP_DELETED. */ suspend_ptr -> ev_return_status = NU_GROUP_DELETED; /* Point to the next suspend structure in the link. */ next_ptr = (EV_SUSPEND *) (suspend_ptr -> ev_suspend_link.cs_next); /* Resume the specified task. */ preempt = preempt | TCC_Resume_Task((NU_TASK *) suspend_ptr -> ev_suspended_task, NU_EVENT_SUSPEND); /* Determine if the next is the same as the current pointer. */ if (next_ptr == event_group -> ev_suspension_list) /* Clear the suspension pointer to signal the end of the list traversal. */ suspend_ptr = NU_NULL; else /* Move the next pointer into the suspend block pointer. */ suspend_ptr = next_ptr; /* Modify current protection. */ TCT_Set_Current_Protect(&EVD_List_Protect); /* Clear the system protection. */ TCT_System_Unprotect(); } /* Determine if preemption needs to occur. */ if (preempt) /* Transfer control to system to facilitate preemption. */ TCT_Control_To_System(); /* Release protection against access to the list of created event groups. */ TCT_Unprotect(); /* Return to user mode */ NU_USER_MODE(); /* Return a successful completion. */ return(NU_SUCCESS);}/*************************************************************************//* *//* FUNCTION *//* *//* EVC_Set_Events *//* *//* DESCRIPTION *//* *//* This function sets event flags within the specified event flag *//* group. Event flags may be ANDed or ORed against the current *//* events of the group. Any task that is suspended on the group *//* that has its request satisfied is resumed. *//* *//* CALLED BY *//* *//* Application *//* EVCE_Set_Events Error checking shell *//* *//* CALLS *//* *//* CSC_Remove_From_List Remove from suspend list *//* [HIC_Make_History_Entry] Make entry in history log *//* TCC_Resume_Task Resume a suspended task *//* [TCT_Check_Stack] Stack checking function *//* TCT_Control_To_System Transfer control to system *//* TCT_System_Protect Protect event group *//* TCT_Unprotect Release protection *//* *//* INPUTS *//* *//* event_group_ptr Event Group control block ptr*//* events Event flag setting *//* operation Operation to perform on the *//* event flag group (AND/OR) *//* *//* OUTPUTS *//* *//* NU_SUCCESS If service is successful *//* *//* HISTORY *//* *//* DATE REMARKS *//* *//* 03-01-1993 Created initial version 1.0 *//* 04-19-1993 Verified version 1.0 *//* 03-01-1994 Changed function interfaces to *//* match those in prototype, *//* added register options, changed *//* protection logic to reduce *//* overhead, resulting in *//* version 1.1 *//* *//* 03-18-1994 Verified version 1.1 *//* 11-19-1996 Corrected SPR190. *//* *//*************************************************************************/STATUS EVC_Set_Events(NU_EVENT_GROUP *event_group_ptr, UNSIGNED events, OPTION operation){R1 EV_GCB *event_group; /* Event control block ptr */R2 EV_SUSPEND *suspend_ptr; /* Pointer to suspension blk */R3 EV_SUSPEND *next_ptr; /* Pointer to next suspend */R4 EV_SUSPEND *last_ptr; /* Last suspension block ptr */UNSIGNED consume; /* Event flags to consume */UNSIGNED compare; /* Event comparison variable */INT preempt; /* Preemption required flag */NU_SUPERV_USER_VARIABLES /* Switch to supervisor mode */ NU_SUPERVISOR_MODE(); /* Move input event group pointer into internal pointer. */ event_group = (EV_GCB *) event_group_ptr;#ifdef NU_ENABLE_STACK_CHECK /* Call stack checking function to check for an overflow condition. */ TCT_Check_Stack();#endif#ifdef NU_ENABLE_HISTORY /* Make an entry that corresponds to this function in the system history log. */ HIC_Make_History_Entry(NU_SET_EVENTS_ID, (UNSIGNED) event_group, (UNSIGNED) events, (UNSIGNED) operation);#endif /* Protect against simultaneous access to the event group. */ TCT_System_Protect(); /* Perform the specified operation on the current event flags in the group. */ if (operation & EV_AND) /* AND the specified events with the current events. */ event_group -> ev_current_events = event_group -> ev_current_events & events; else /* OR the specified events with the current events. */ event_group -> ev_current_events = event_group -> ev_current_events | events;#ifdef INCLUDE_PROVIEW _RTProf_DumpEventGroup(RT_PROF_SET_EVENTS,event_group , RT_PROF_OK);#endif /*INCLUDE_PROVIEW*/ /* Determine if there are any tasks suspended for events from this event flag group. */ if (event_group -> ev_suspension_list) { /* Initialize the consumption bits to 0. */ consume = 0; /* Now, walk the chain of tasks suspended on this event flag group to determine if any of their requests can be satisfied. */ suspend_ptr = event_group -> ev_suspension_list; /* Setup a pointer to the last suspension block. */ last_ptr = (EV_SUSPEND *) suspend_ptr -> ev_suspend_link.cs_previous; /* Clear the preempt flag. */ preempt = 0; do { /* Determine if this request has been satisfied. */ /* First, find the event flags in common. */ compare = event_group -> ev_current_events & suspend_ptr -> ev_requested_events; /* Second, determine if all the event flags must match. */ if (suspend_ptr -> ev_operation & EV_AND) /* Yes, an AND condition is present. All requested events must be present. */ compare = (compare == suspend_ptr -> ev_requested_events); /* Setup the next pointer. Note that this must be done before the suspended task is resumed, since its suspend block could get corrupted. */ next_ptr = (EV_SUSPEND *) suspend_ptr -> ev_suspend_link.cs_next; /* If compare is non-zero, the suspended task's event request is satisfied. */ if (compare) { /* Decrement the number of tasks waiting counter. */ event_group -> ev_tasks_waiting--; /* Determine if consumption is requested. */ if (suspend_ptr -> ev_operation & EV_CONSUME) /* Keep track of the event flags to consume. */ consume = consume | suspend_ptr -> ev_requested_events; /* Remove the first suspended block from the list. */ CSC_Remove_From_List((CS_NODE **) &(event_group -> ev_suspension_list), &(suspend_ptr -> ev_suspend_link)); /* Setup the appropriate return value. */ suspend_ptr -> ev_return_status = NU_SUCCESS; suspend_ptr -> ev_actual_events = event_group -> ev_current_events; /* Resume the suspended task. */ preempt = preempt | TCC_Resume_Task((NU_TASK *) suspend_ptr -> ev_suspended_task, NU_EVENT_SUSPEND); } /* Determine if there is another suspension block to examine. */ if (suspend_ptr != last_ptr) /* More to examine in the suspension list. Look at the next suspend block. */ suspend_ptr = next_ptr; else /* End of the list has been reached. Set the suspend pointer to NULL to end the search. */ suspend_ptr = NU_NULL; } while (suspend_ptr); /* Apply all of the gathered consumption bits. */ event_group -> ev_current_events = event_group -> ev_current_events & ~consume; /* Determine if a preempt condition is present. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -