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

📄 tcc.c

📁 抢占
💻 C
📖 第 1 页 / 共 5 页
字号:
                suspend_protect =  task -> tc_suspend_protect;
                
                /* Save the current status.  */
                status =           task -> tc_status;
                
                /* Release protection on system structures.  */
                TCT_Unprotect();
                
                /* Determine if there was a suspension protection.  If so
                   protect it first before the scheduling list protection.
                   This avoids a deadlock situation.  */
                if (suspend_protect)
                
                    /* Protect the terminated task's last suspension 
                       structures.  */
                    TCT_Protect(suspend_protect);
                    
                /* Protect the system structures again.  */
                TCT_Protect(&TCD_System_Protect);
                
                /* Now determine if the same suspension is in force.  */
                if ((task -> tc_status == status) &&
                    (task -> tc_suspend_protect == suspend_protect))
                {
                
                    /* Yes, same suspension is in force.  */
                    
                    /* Call cleanup routine, if there is one.  */
                    if (task -> tc_cleanup)
        
                        /* Call cleanup function.  */
                        (*(task -> tc_cleanup)) (task -> tc_cleanup_info);

                    /* Status the task as terminated.  */
                    task -> tc_status =  NU_TERMINATED;

                    /* Determine if there is a timer active.  */
                    if (task -> tc_timer_active) 
                    {
        
                        /* Call the stop timer function.  */
                        TMC_Stop_Task_Timer(&(task -> tc_timer_control)); 
                       
                        /* Clear the timer active flag.  */
                        task -> tc_timer_active =  NU_FALSE;
                    }
                }
                
                /* Cleanup the protection.  */
                if (suspend_protect)
                {

                    /* Release specific protection.  */
                    TCT_Unprotect_Specific(suspend_protect);
                
                    /* Clear the suspend protect field.  */
                    task -> tc_suspend_protect =  NU_NULL;
                }
                    
                /* Release current protection.  */
                TCT_Unprotect();
            }

            /* Protect the scheduling list again.  */
            TCT_Protect(&TCD_System_Protect);
        }
        
        /* Release the protection.  */
        TCT_Unprotect();
    }
        
    /* Return successful completion.  */
    return(NU_SUCCESS);
}


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      TCC_Resume_Task                                                  */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function resumes a previously suspended task.  The task     */
/*      task must currently be suspended for the same reason indicated   */
/*      by this request.  If the task resumed is higher priority than    */
/*      the calling task and the current task is preemptable, this       */
/*      function returns a value of NU_TRUE.  Otherwise, if no           */
/*      preemption is required, a NU_FALSE is returned.                  */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      William E. Lamie, Accelerated Technology, Inc.                   */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      Other Components                                                 */
/*      TCC_Resume_Service                  Resume service function      */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      [TCT_Check_Stack]                   Stack checking function      */
/*      TCT_Set_Current_Protect             Set current protection field */
/*      TCT_Set_Execute_Task                Set TCD_Execute_Task pointer */
/*      TMC_Stop_Task_Timer                 Stop task timer              */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      task_ptr                            Task control block pointer   */
/*      suspend_type                        Type of suspension to lift   */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      NU_TRUE                             A higher priority task is    */
/*                                            ready to execute           */
/*      NU_FALSE                            No change in the task to     */
/*                                            execute                    */
/*                                                                       */
/* 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        09-19-1993      Corrected an initialization      */
/*                                        problem of de-referencing a    */
/*                                        NULL pointer, resulting in     */
/*                                        version 1.0d                   */
/*      D. Lamie        09-19-1993      Verified version 1.0d            */
/*      W. Lamie        03-01-1994      Modified function interface,     */
/*                                        added register optimizations,  */
/*                                        modified protection logic to   */
/*                                        assume that system protection  */
/*                                        is already in force, resulting */
/*                                        in version 1.1                 */
/*      R. Pfaff -                                                       */
/*      D. Lamie        03-18-1994      Verified version 1.1             */
/*      S. Murrill      10-29-1997      Changed so that tc_cleanup,      */
/*                                      tc_cleanup_info, and             */
/*                                      tc_suspend_protect are cleared   */
/*                                      only if a signal is not active   */
/*                                      (SPR115)                         */
/*      M. Trippi       03-20-1998      Corrected SPR455.                */
/*                                                                       */
/*************************************************************************/
STATUS  TCC_Resume_Task(NU_TASK *task_ptr, OPTION suspend_type)
{

R1 TC_TCB      *task;                       /* Task control block ptr    */
R2 TC_TCB      *head;                       /* Pointer to priority list  */
STATUS          status =  NU_FALSE;         /* Status variable           */


    /* 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


    /* Check to see if the task is suspended for the reason that this
       resume is attempting to clear.  */
    if (task -> tc_status == suspend_type)
    {
    
        /* Yes, this resume call is valid.  */
        
        /* If signals are not active, clear any suspend or cleanup 
           information (SPR115).  */
        if (!task -> tc_signal_active)
        {        
            task -> tc_suspend_protect =        NU_NULL;
            task -> tc_cleanup =                NU_NULL;
            task -> tc_cleanup_info =           NU_NULL;
        }

        /* Determine if there is a timer active and the task is not being
           resumed to handle a signal.  */
        if ((task -> tc_timer_active) && (!task -> tc_signal_active))
        {
        
            /* Call the stop timer function.  */
            TMC_Stop_Task_Timer(&(task -> tc_timer_control)); 
            
            /* Clear the timer active flag.  */
            task -> tc_timer_active =  NU_FALSE;
        }
        
        /* Check to see if there is a pending pure suspension.  If so, 
           change the cause of the suspension and leave in a suspended 
           state.  */
        if (task -> tc_delayed_suspend)
        {
        
            /* Leave suspended but change the task's status and clear the
               delayed suspension flag.  */
            task -> tc_delayed_suspend =  NU_FALSE;
            task -> tc_status =  NU_PURE_SUSPEND;
        }
        else
        {
        
            /* Lift the suspension of the specified task.  */
            
            /* Clear the status of the task.  */
            task -> tc_status =  NU_READY;
            
            /* Link the task into the appropriate priority list.  */
            head =  *(task -> tc_priority_head);
            
            /* Determine if the list is non-empty.  */
            if (head)
            {
            
                /* Add the new TCB to the end of the ready list.  */
                task -> tc_ready_previous =      head -> tc_ready_previous;
                (task -> tc_ready_previous) -> tc_ready_next =  task;
                task -> tc_ready_next =          head;
                (task -> tc_ready_next) -> tc_ready_previous =  task;
                
                /* Note that the priority bit map does not need to be
                   modified since there are other active tasks at the 
                   same priority.  */
            }
            else
            {
            
                /* Add the new TCB to an empty list.  */
                task -> tc_ready_previous =  task;
                task -> tc_ready_next =      task;
                *(task -> tc_priority_head)= task;

                /* Update the priority group bit map to indicate that this
                   priority now has a task ready.  */
                TCD_Priority_Groups =  
                        TCD_Priority_Groups | (task -> tc_priority_group);
                

⌨️ 快捷键说明

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