⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mbc.c

📁 test file nucleus source
💻 C
📖 第 1 页 / 共 4 页
字号:
    /* Make an entry that corresponds to this function in the system history       log.  */    HIC_Make_History_Entry(NU_RECEIVE_FROM_MAILBOX_ID, (UNSIGNED) mailbox,                                       (UNSIGNED) message, (UNSIGNED) suspend);#endif    /* Initialize the status as successful.  */    status =  NU_SUCCESS;    /* Protect against simultaneous access to the mailbox.  */    TCT_System_Protect();    /* Determine if the mailbox is empty or full.  */    if (mailbox -> mb_message_present)    {        /* Copy message from mailbox into the caller's area.  */        /* Setup the source and destination pointers.  */        source_ptr =       &(mailbox -> mb_message_area[0]);        destination_ptr =  (UNSIGNED *) message;        /* Copy the message directly into the waiting task's           destination.  */        *destination_ptr =        *source_ptr;        *(destination_ptr + 1) =  *(source_ptr + 1);        *(destination_ptr + 2) =  *(source_ptr + 2);        *(destination_ptr + 3) =  *(source_ptr + 3);        /* Determine if another task is waiting to place something into the           mailbox.  */        if (mailbox -> mb_suspension_list)        {            /* Yes, another task is waiting to send something to the               mailbox.  */            /* Decrement the number of tasks waiting counter.  */            mailbox -> mb_tasks_waiting--;#ifdef INCLUDE_PROVIEW            _RTProf_DumpMailBox(RT_PROF_RECEIVE_FROM_MAILBOX,mailbox,RT_PROF_OK);#endif /* INCLUDE_PROVIEW */            /* Remove the first suspended block from the list.  */            suspend_ptr =  mailbox -> mb_suspension_list;            CSC_Remove_From_List((CS_NODE **)                &(mailbox -> mb_suspension_list),                                &(suspend_ptr -> mb_suspend_link));            /* Setup the source and destination pointers.  */            source_ptr =       suspend_ptr -> mb_message_area;            destination_ptr =  &(mailbox -> mb_message_area[0]);            /* Copy the message directly into the waiting task's               destination.  */            *destination_ptr =        *source_ptr;            *(destination_ptr + 1) =  *(source_ptr + 1);            *(destination_ptr + 2) =  *(source_ptr + 2);            *(destination_ptr + 3) =  *(source_ptr + 3);            /* Setup the appropriate return value.  */            suspend_ptr -> mb_return_status =  NU_SUCCESS;            /* Resume the suspended task.  */            preempt =               TCC_Resume_Task((NU_TASK *) suspend_ptr -> mb_suspended_task,                                                       NU_MAILBOX_SUSPEND);            /* Determine if a preempt condition is present.  */            if (preempt)                /* Transfer control to the system if the resumed task function                   detects a preemption condition.  */                TCT_Control_To_System();        }        else        {            /* Clear the message present flag.  */            mailbox -> mb_message_present =  NU_FALSE;#ifdef INCLUDE_PROVIEW            _RTProf_DumpMailBox(RT_PROF_RECEIVE_FROM_MAILBOX,mailbox,RT_PROF_OK);#endif /* INCLUDE_PROVIEW */        }    }    else    {        /* Mailbox is empty.  Determine if suspension is required.  */        if (suspend)        {            /* Suspension is required.  */            /* Increment the number of tasks waiting on the mailbox counter. */            mailbox -> mb_tasks_waiting++;#ifdef INCLUDE_PROVIEW            _RTProf_DumpMailBox(RT_PROF_RECEIVE_FROM_MAILBOX,mailbox,RT_PROF_WAIT);#endif /* INCLUDE_PROVIEW */            /* Setup the suspend block and suspend the calling task.  */            suspend_ptr =  &suspend_block;            suspend_ptr -> mb_mailbox =                  mailbox;            suspend_ptr -> mb_suspend_link.cs_next =     NU_NULL;            suspend_ptr -> mb_suspend_link.cs_previous = NU_NULL;            suspend_ptr -> mb_message_area =             (UNSIGNED *) message;            task =                            (TC_TCB *) TCT_Current_Thread();            suspend_ptr -> mb_suspended_task =           task;            /* Determine if priority or FIFO suspension is associated with the               mailbox.  */            if (mailbox -> mb_fifo_suspend)            {                /* FIFO suspension is required.  Link the suspend block into                   the list of suspended tasks on this mailbox.  */                CSC_Place_On_List((CS_NODE **) &(mailbox ->mb_suspension_list),                                        &(suspend_ptr -> mb_suspend_link));            }            else            {                /* Get the priority of the current thread so the suspend block                   can be placed in the appropriate place.  */                suspend_ptr -> mb_suspend_link.cs_priority =                                                       TCC_Task_Priority(task);                CSC_Priority_Place_On_List((CS_NODE **)                        &(mailbox -> mb_suspension_list),                                        &(suspend_block.mb_suspend_link));            }            /* Finally, suspend the calling task. Note that the suspension call               automatically clears the protection on the mailbox.  */            TCC_Suspend_Task((NU_TASK *) task, NU_MAILBOX_SUSPEND,                                        MBC_Cleanup, &suspend_block, suspend);            /* Pickup the return status.  */            status =  suspend_ptr -> mb_return_status;        }        else        {            /* Return a status of NU_MAILBOX_EMPTY because there is               nothing in the mailbox.  */            status =  NU_MAILBOX_EMPTY;#ifdef INCLUDE_PROVIEW            _RTProf_DumpMailBox(RT_PROF_RECEIVE_FROM_MAILBOX,mailbox,RT_PROF_FAIL);#endif /* INCLUDE_PROVIEW */        }    }    /* Release protection.  */    TCT_Unprotect();    /* Return to user mode */    NU_USER_MODE();    /* Return the completion status.  */    return(status);}/*************************************************************************//*                                                                       *//* FUNCTION                                                              *//*                                                                       *//*      MBC_Cleanup                                                      *//*                                                                       *//* DESCRIPTION                                                           *//*                                                                       *//*      This function is responsible for removing a suspension block     *//*      from a mailbox.  It is not called unless a timeout or a task     *//*      terminate is in progress.  Note that protection is already in    *//*      effect - the same protection at suspension time.                 *//*                                                                       *//* CALLED BY                                                             *//*                                                                       *//*      TCC_Timeout                         Task timeout                 *//*      TCC_Terminate                       Task terminate               *//*                                                                       *//* CALLS                                                                 *//*                                                                       *//*      CSC_Remove_From_List                Remove suspend block from    *//*                                            the suspension list        *//*                                                                       *//* INPUTS                                                                *//*                                                                       *//*      information                         Pointer to suspend block     *//*                                                                       *//* OUTPUTS                                                               *//*                                                                       *//*      None                                                             *//*                                                                       *//* HISTORY                                                               *//*                                                                       *//*         DATE                    REMARKS                               *//*                                                                       *//*      03-01-1993      Created initial version 1.0                      *//*      04-19-1993      Verified version 1.0                             *//*                                                                       *//*************************************************************************/VOID  MBC_Cleanup(VOID *information){MB_SUSPEND      *suspend_ptr;               /* Suspension block pointer  */NU_SUPERV_USER_VARIABLES    /* Switch to supervisor mode */    NU_SUPERVISOR_MODE();    /* Use the information pointer as a suspend pointer.  */    suspend_ptr =  (MB_SUSPEND *) information;    /* By default, indicate that the service timed-out.  It really does not       matter if this function is called from a terminate request since       the task does not resume.  */    suspend_ptr -> mb_return_status =  NU_TIMEOUT;    /* Decrement the number of tasks waiting counter.  */    (suspend_ptr -> mb_mailbox) -> mb_tasks_waiting--;    /* Unlink the suspend block from the suspension list.  */    CSC_Remove_From_List((CS_NODE **)                &((suspend_ptr -> mb_mailbox) -> mb_suspension_list),                                &(suspend_ptr -> mb_suspend_link));    /* Return to user mode */    NU_USER_MODE();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -