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

📄 tcs.c

📁 test file nucleus source
💻 C
📖 第 1 页 / 共 4 页
字号:
               /* 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 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);               /* Update the sub-priority bit map to show that this priority                  is ready.  */               *(task -> tc_sub_priority_ptr) =                   (*(task -> tc_sub_priority_ptr)) | task -> tc_sub_priority;           }           /* Determine the highest priority task in the system.  */           if (TCD_Priority_Groups & TC_HIGHEST_MASK)               /* Base of sub-group is 0.  */               index =  0;           else if (TCD_Priority_Groups & TC_NEXT_HIGHEST_MASK)               /* Base of sub-group is 8.  */               index =  8;           else if (TCD_Priority_Groups & TC_NEXT_LOWEST_MASK)               /* Base of sub-group is 16.  */               index =  16;           else               /* Base of sub-group is 24.  */               index =  24;           /* Calculate the highest available priority.  */           index =  index + TCD_Lowest_Set_Bit[(INT)                   ((TCD_Priority_Groups >> index) & TC_HIGHEST_MASK)];           /* Get the mask of the priority within the group of 8 priorities.  */           temp =  TCD_Sub_Priority_Groups[index];           /* Calculate the actual priority.  */           TCD_Highest_Priority =  (index << 3) + TCD_Lowest_Set_Bit[temp];           /* Check for preemption.  */           if ((TCD_Highest_Priority <= ((INT) TCD_Execute_Task -> tc_priority))               && (TCD_Execute_Task -> tc_preemption))           {               /* Update the current task pointer.  */               TCT_Set_Execute_Task(TCD_Priority_List[TCD_Highest_Priority]);               /* Now, check and see if the current thread is a task.                  If so, return a status that indicates a context                  switch is needed.  */               if ((TCD_Current_Thread) &&                  (((TC_TCB *) TCD_Current_Thread) -> tc_id == TC_TASK_ID))                   /* Transfer control to the system.  */                   TCT_Control_To_System();           }       }       else       {           /* Just modify the priority.  */           task -> tc_priority =  new_priority;           /* Build the other priority information.  */           task -> tc_priority =      new_priority;           task -> tc_priority_head = &(TCD_Priority_List[new_priority]);           task -> tc_sub_priority =  (DATA_ELEMENT) (1 << (new_priority & 7));           task -> tc_priority_group =   ((UNSIGNED) 1) << (new_priority >> 3);           task -> tc_sub_priority_ptr =                   &(TCD_Sub_Priority_Groups[(new_priority >> 3)]);       }#ifdef INCLUDE_PROVIEW        _RTProf_DumpTask(task,RT_PROF_CHANGE_PRIORITY);#endif    }    /* Release the protection of the scheduling list.  */    TCT_Unprotect();    /* Return to user mode */    NU_USER_MODE();    /* Return the old priority.  */    return(old_priority);}/*************************************************************************//*                                                                       *//* FUNCTION                                                              *//*                                                                       *//*      TCS_Change_Preemption                                            *//*                                                                       *//* DESCRIPTION                                                           *//*                                                                       *//*      This function changes the preemption posture of the calling      *//*      task.  Preemption for a task may be enabled or disabled.  If     *//*      it is disabled, the task runs until it suspends or relinquishes. *//*      If a preemption is pending, a call to this function to enable    *//*      preemption causes a context switch.                              *//*                                                                       *//* CALLED BY                                                             *//*                                                                       *//*      Application                                                      *//*      TCSE_Change_Preemption              Error checking function      *//*                                                                       *//* CALLS                                                                 *//*                                                                       *//*      [HIC_Make_History_Entry]            Make entry in history log    *//*      [TCT_Check_Stack]                   Stack checking function      *//*      TCT_Control_To_System               Transfer control to system   *//*      TCT_Protect                         Protect scheduling info      *//*      TCT_Set_Execute_Task                Set TCD_Execute_Task pointer *//*      TCT_Unprotect                       Release protection of info   *//*                                                                       *//* INPUTS                                                                *//*                                                                       *//*      preempt                             Preempt selection parameter  *//*                                                                       *//* OUTPUTS                                                               *//*                                                                       *//*      old_preempt                         Original preempt value       *//*                                                                       *//* HISTORY                                                               *//*                                                                       *//*        DATE                    REMARKS                                *//*                                                                       *//*      03-01-1993      Created initial version 1.0                      *//*      04-19-1993      Verified version 1.0                             *//*      03-01-1994      Modified protection logic,                       *//*                      resulting in version 1.1                         *//*                                                                       *//*      03-18-1994      Verified version 1.1                             *//*                                                                       *//*************************************************************************/OPTION   TCS_Change_Preemption(OPTION preempt){TC_TCB         *task;                       /* Pointer to task           */OPTION          old_preempt;NU_SUPERV_USER_VARIABLES    /* Switch to supervisor mode */    NU_SUPERVISOR_MODE();#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_CHANGE_PREEMPTION_ID, (UNSIGNED) preempt,                                        (UNSIGNED) 0, (UNSIGNED) 0);#endif    /* Protect the scheduling information.  */    TCT_Protect(&TCD_System_Protect);    /* Pickup the current thread and place it in the task pointer.  */    task =  (TC_TCB *) TCD_Current_Thread;    /* Save the old preempt value.  */    if (task -> tc_preemption)        /* Previously enabled.  */        old_preempt =  NU_PREEMPT;    else        /* Previously disabled.  */        old_preempt =  NU_NO_PREEMPT;    /* Process the new value.  */    if (preempt == NU_NO_PREEMPT)        /* Disable preemption.  */        TCD_Execute_Task -> tc_preemption =  NU_FALSE;    else    {        /* Enable preemption.  */        task -> tc_preemption =  NU_TRUE;        /* Check for a preemption condition.  */        if ((task == TCD_Execute_Task) &&            (TCD_Highest_Priority < ((INT) TCD_Execute_Task -> tc_priority)))        {            /* Preempt the current task.  */            TCT_Set_Execute_Task(TCD_Priority_List[TCD_Highest_Priority]);            /* Transfer control to the system.  */            TCT_Control_To_System();        }    }#ifdef INCLUDE_PROVIEW    _RTProf_DumpTask(task,RT_PROF_CHANGE_PREEMPTION);#endif    /* Release protection of information.  */    TCT_Unprotect();    /* Return to user mode */    NU_USER_MODE();    /* Return the previous preemption posture.  */    return(old_preempt);}/*************************************************************************//*                                                                       *//* FUNCTION                                                              *//*                                                                       *//*      TCS_Change_Time_Slice                                            *//*                                                                       *//* DESCRIPTION                                                           *//*                                                                       *//*      This function changes the time slice of the specified task.  A   *//*      time slice value of 0 disables time slicing.                     *//*                                                                       *//* CALLED BY                                                             *//*                                                                       *//*      Application                                                      *//*      TCES_Change_Preemption              Error checking function      *//*                                                                       *//* CALLS                                                                 *//*                                                                       *//*      [HIC_Make_History_Entry]            Make entry in history log    *//*      [TCT_Check_Stack]                   Stack checking function      *//*      TCT_Protect                         Protect scheduling info      *//*      TCT_Unprotect                       Release protection of info   *//*                                                                       *//* INPUTS                                                                *//*                                                                       *//*      task_ptr                            Task control block pointer   *//*      time_slice                          New time slice value         *//*                                                                       *//* OUTPUTS                                                               *//*                                                                       *//*      old_time_slice                      Original time slice value    *//*                                                                       *//* HISTORY                                                               *//*                                                                       *//*         DATE                    REMARKS                               *//*                                                                       *//*      03-01-1993      Created initial version 1.0                      *//*      04-19-1993      Verified version 1.0                             *//*      03-01-1994      Modified function interface,                     *//*                      added register optimizations,                    *//*                      modified protection logic,                       *//*                      resulting in version 1.1                         *//*                                                                       *//*      03-18-1994      Verified version 1.1                             *//*                                                                       *//*************************************************************************/UNSIGNED   TCS_Change_Time_Slice(NU_TASK *task_ptr, UNSIGNED time_slice){TC_TCB         *task;                       /* Task control block ptr    */UNSIGNED        old_time_slice;             /* Old time slice value      */NU_SUPERV_USER_VARIABLES    /* Switch to supervisor mode */    NU_SUPERVISOR_MODE();    /* Move input task control block pointer into internal pointer.  */    task =  (TC_TCB *) task_ptr;

⌨️ 快捷键说明

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