📄 mbc.c
字号:
/* [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_Protect Protect created list *//* TCT_Set_Current_Protect Setup current protection ptr *//* TCT_System_Protect Protect against system access*//* TCT_System_Unprotect Release system protection *//* TCT_Unprotect Release protection *//* *//* INPUTS *//* *//* mailbox_ptr Mailbox control block pointer*//* *//* OUTPUTS *//* *//* NU_SUCCESS *//* *//* HISTORY *//* *//* DATE REMARKS *//* *//* 03-01-1993 Created initial version 1.0 *//* 04-19-1993 Verified version 1.0 *//* 03-01-1994 Changed function interface to *//* match the prototype, added *//* register variable logic, *//* optimized protection logic, *//* resulting in version 1.1 *//* *//* 03-18-1994 Verified version 1.1 *//* *//*************************************************************************/STATUS MBC_Delete_Mailbox(NU_MAILBOX *mailbox_ptr){R1 MB_MCB *mailbox; /* Mailbox control block ptr */MB_SUSPEND *suspend_ptr; /* Suspend block pointer */MB_SUSPEND *next_ptr; /* Next suspend block pointer*/STATUS preempt; /* Status for resume call */NU_SUPERV_USER_VARIABLES /* Switch to supervisor mode */ NU_SUPERVISOR_MODE(); /* Move input mailbox pointer into internal pointer. */ mailbox = (MB_MCB *) mailbox_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_DELETE_MAILBOX_ID, (UNSIGNED) mailbox, (UNSIGNED) 0, (UNSIGNED) 0);#endif /* Call protection just in case another thread is using the mailbox. */ TCT_System_Protect();#ifdef INCLUDE_PROVIEW _RTProf_DumpMailBox(RT_PROF_DELETE_MAILBOX,mailbox,RT_PROF_OK);#endif /* INCLUDE_PROVIEW */ /* Clear the mailbox ID. */ mailbox -> mb_id = 0; /* Clear protection. */ TCT_Unprotect(); /* Protect against access to the list of created mailboxes. */ TCT_Protect(&MBD_List_Protect); /* Remove the mailbox from the list of created mailboxes. */ CSC_Remove_From_List(&MBD_Created_Mailboxes_List, &(mailbox -> mb_created)); /* Decrement the total number of created mailboxes. */ MBD_Total_Mailboxes--; /* Pickup the suspended task pointer list. */ suspend_ptr = mailbox -> mb_suspension_list; /* Walk the chain task(s) currently suspended on the mailbox. */ preempt = 0; while (suspend_ptr) { /* Protect against system access. */ TCT_System_Protect(); /* Resume the suspended task. Insure that the status returned is NU_MAILBOX_DELETED. */ suspend_ptr -> mb_return_status = NU_MAILBOX_DELETED; /* Point to the next suspend structure in the link. */ next_ptr = (MB_SUSPEND *) (suspend_ptr -> mb_suspend_link.cs_next); /* Resume the specified task. */ preempt = preempt | TCC_Resume_Task((NU_TASK *) suspend_ptr -> mb_suspended_task, NU_MAILBOX_SUSPEND); /* Determine if the next is the same as the head pointer. */ if (next_ptr == mailbox -> mb_suspension_list) /* Clear the suspension pointer to signal the end of the list traversal. */ suspend_ptr = NU_NULL; else /* Position the suspend pointer to the next suspend block. */ suspend_ptr = next_ptr; /* Setup current protection pointer. */ TCT_Set_Current_Protect(&MBD_List_Protect); /* Unprotect 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 mailboxes. */ TCT_Unprotect(); /* Return to user mode */ NU_USER_MODE(); /* Return a successful completion. */ return(NU_SUCCESS);}/*************************************************************************//* *//* FUNCTION *//* *//* MBC_Send_To_Mailbox *//* *//* DESCRIPTION *//* *//* This function sends a 4-word message to the specified mailbox. *//* If there are one or more tasks suspended on the mailbox for a *//* message, the message is copied into the message area of the *//* first task waiting and that task is resumed. If the mailbox *//* is full, suspension of the calling task is possible. *//* *//* CALLED BY *//* *//* Application *//* MBCE_Send_To_Mailbox Error checking shell *//* *//* CALLS *//* *//* CSC_Place_On_List Place on suspend list *//* CSC_Priority_Place_On_List Place on priority list *//* CSC_Remove_From_List Remove from suspend list *//* [HIC_Make_History_Entry] Make entry in history log *//* TCC_Resume_Task Resume a suspended task *//* TCC_Suspend_Task Suspend calling task *//* TCC_Task_Priority Pickup task's priority *//* [TCT_Check_Stack] Stack checking function *//* TCT_Control_To_System Transfer control to system *//* TCT_Current_Thread Pickup current thread pointer*//* TCT_System_Protect Protect against system access*//* TCT_Unprotect Release protection *//* *//* INPUTS *//* *//* mailbox_ptr Mailbox control block pointer*//* message Pointer to message to send *//* suspend Suspension option if full *//* *//* OUTPUTS *//* *//* NU_SUCCESS If service is successful *//* NU_MAILBOX_FULL If mailbox is currently full *//* NU_TIMEOUT If timeout on service expires*//* NU_MAILBOX_DELETED If mailbox is deleted during *//* suspension *//* NU_MAILBOX_RESET If mailbox is deleted during *//* suspension *//* *//* HISTORY *//* *//* DATE REMARKS *//* *//* 03-01-1993 Created initial version 1.0 *//* 04-19-1993 Verified version 1.0 *//* 03-01-1994 Changed function interface to *//* match the prototype, added *//* register variable logic, *//* optimized protection logic, *//* resulting in version 1.1 *//* *//* 03-18-1994 Verified version 1.1 *//* *//*************************************************************************/STATUS MBC_Send_To_Mailbox(NU_MAILBOX *mailbox_ptr, VOID *message, UNSIGNED suspend){R1 MB_MCB *mailbox; /* Mailbox control block ptr */MB_SUSPEND suspend_block; /* Allocate suspension block */R2 MB_SUSPEND *suspend_ptr; /* Pointer to suspend block */R3 UNSIGNED *source_ptr; /* Pointer to source */R4 UNSIGNED *destination_ptr; /* Pointer to destination */TC_TCB *task; /* Task pointer */STATUS preempt; /* Preempt flag */STATUS status; /* Completion status */NU_SUPERV_USER_VARIABLES /* Switch to supervisor mode */ NU_SUPERVISOR_MODE(); /* Move input mailbox pointer into internal pointer. */ mailbox = (MB_MCB *) mailbox_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_SEND_TO_MAILBOX_ID, (UNSIGNED) mailbox, (UNSIGNED) message, (UNSIGNED) suspend);#endif /* Initialize the status as successful. */ status = NU_SUCCESS;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -