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

📄 tcc.c

📁 抢占
💻 C
📖 第 1 页 / 共 5 页
字号:

/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      TCC_Reset_Task                                                   */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function resets the specified task.  Note that a task reset */
/*      can only be performed on tasks in a finished or terminated state.*/
/*      The task is left in an unconditional suspended state.            */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      William E. Lamie, Accelerated Technology, Inc.                   */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      Application                                                      */
/*      TCCE_Reset_Task                     Error checking shell         */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      [HIC_Make_History_Entry]            Make entry in history log    */
/*      TCT_Build_Task_Stack                Build an initial task stack  */
/*      [TCT_Check_Stack]                   Stack checking function      */
/*      TCT_Protect                         Protect created task list    */
/*      TCT_Unprotect                       Release protection of list   */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      task_ptr                            Task control block pointer   */
/*      argc                                Optional task parameter      */
/*      argv                                Optional task parameter      */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      NU_SUCCESS                          Indicates successful request */
/*      NU_NOT_TERMINATED                   Indicates task was not       */
/*                                            finished or terminated     */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*      W. Lamie        03-01-1993      Created initial version 1.0      */
/*      D. Lamie        04-19-1993      Verified version 1.0             */
/*      W. Lamie        03-01-1994      Modified function interface,     */
/*                                        added register optimizations,  */
/*                                        added system protection logic, */
/*                                        resulting in version 1.1       */
/*      R. Pfaff -                                                       */
/*      D. Lamie        03-18-1994      Verified version 1.1             */
/*                                                                       */
/*************************************************************************/
STATUS  TCC_Reset_Task(NU_TASK *task_ptr, UNSIGNED argc, VOID *argv)
{

R1 TC_TCB      *task;                       /* Task control block ptr   */
STATUS          status;                     /* Status of the request    */



    /* Move input task pointer into internal pointer.  */
    task =  (TC_TCB *) task_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_RESET_TASK_ID, (UNSIGNED) task, 
                                        (UNSIGNED) argc, (UNSIGNED) argv);

#endif

    /* Protect system structures.  */
    TCT_Protect(&TCD_System_Protect);
    
    /* Determine if the task is in the proper state.  */
    if ((task -> tc_status == NU_FINISHED) || 
                        (task -> tc_status == NU_TERMINATED))
    {
    
        /* Yes, a valid reset is present.  Indicate this in the status.  */
        status =  NU_SUCCESS;

        /* Fill in the new argument information and reset some of the other
           fields.  */
        task -> tc_argc =                   argc;
        task -> tc_argv =                   argv;
        task -> tc_status =                 NU_PURE_SUSPEND;
        task -> tc_delayed_suspend =        NU_FALSE;
        task -> tc_scheduled =              0;
        task -> tc_stack_minimum =          task -> tc_stack_size;
    
        /* Build a stack frame for this task by calling 
           TCT_Build_Task_Stack.  */
        TCT_Build_Task_Stack(task);
    }
    else
    
        /* The requested task is not in a finished or terminated state.  */
        status =  NU_NOT_TERMINATED;
        
    /* Release the protection.  */
    TCT_Unprotect();

    /* Return completion status.  */
    return(status);
}


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      TCC_Terminate_Task                                               */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function terminates the specified task.  If the task is     */
/*      already terminated, this function does nothing.  If the task     */
/*      to terminate is currently suspended, the specified cleanup       */
/*      routine is also invoked to cleanup suspension data structures.   */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      William E. Lamie, Accelerated Technology, Inc.                   */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      Application                                                      */
/*      TCCE_Terminate_Task                 Error checking shell         */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      Cleanup routine                     Task's suspend cleanup funct */
/*      [HIC_Make_History_Entry]            Make entry in history log    */
/*      TCC_Suspend_Task                    Suspend a ready task         */
/*      [TCT_Check_Stack]                   Stack checking function      */
/*      TCT_Protect                         Protect created task list    */
/*      TCT_Unprotect                       Release protection of list   */
/*      TCT_Unprotect_Specific              Specific unprotection        */
/*      TMC_Stop_Task_Timer                 Stop a task timer            */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      task_ptr                            Task control block pointer   */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      NU_SUCCESS                                                       */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*      W. Lamie        03-01-1993      Created initial version 1.0      */
/*      D. Lamie        04-19-1993      Verified version 1.0             */
/*      W. Lamie        03-01-1994      Modified function interface,     */
/*                                        added register optimizations,  */
/*                                        added system protection logic, */
/*                                        resulting in version 1.1       */
/*      R. Pfaff -                                                       */
/*      D. Lamie        03-18-1994      Verified version 1.1             */
/*                                                                       */
/*************************************************************************/
STATUS  TCC_Terminate_Task(NU_TASK *task_ptr)
{

R1 TC_TCB      *task;                       /* Task control block ptr    */
TC_PROTECT     *suspend_protect;            /* Suspension protection ptr */
DATA_ELEMENT    status;                     /* Task status               */


    /* Move task pointer into internal pointer.  */
    task =  (TC_TCB *) task_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_TERMINATE_TASK_ID, (UNSIGNED) task, 
                                        (UNSIGNED) 0, (UNSIGNED) 0);

#endif

    /* Determine if the calling task is the current task.  */
    if (task == (TC_TCB *) TCD_Current_Thread)
    {

        /* Protect system  data structures.  */
        TCT_Protect(&TCD_System_Protect);

        /* Suspend the calling task with the NU_TERMINATED status.  */
        TCC_Suspend_Task(task_ptr, NU_TERMINATED, NU_NULL, NU_NULL, 
                                                            NU_SUSPEND);
    
        /* No need to un-protect, since control never comes back to this
           point and the protection is cleared in TCT_Control_To_System.  */
    }
    else
    {
    
        /* Protect scheduling structures.  */
        TCT_Protect(&TCD_System_Protect);
    
        /* Keep trying to terminate the specified task until its status 
           indicates that it is terminated or finished.  */
        while ((task -> tc_status != NU_FINISHED) &&
                  task -> tc_status != NU_TERMINATED)
        {
        
            /* Is the task in a ready state?  */
            if (task -> tc_status == NU_READY)
            {
            
                /* Terminate the specified task.  */                
                TCC_Suspend_Task(task_ptr, NU_TERMINATED, NU_NULL,
                                                        NU_NULL,NU_SUSPEND);

                /* Clear system protection.  */
                TCT_Unprotect();
            }
            else
            {
            
                /* Task is suspended currently.  Pickup the suspension 
                   protection.  */

⌨️ 快捷键说明

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