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

📄 rm.c

📁 NecluesRTX RTOS的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function is used to unlink a suspension structure from a   */
/*      specified linked list.                                          */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*       RM_Release_Resource                Release a resource          */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      ptr_head_ptr                        Pointer to list head ptr    */
/*      ptr_tail_ptr                        Pointer to list tail ptr    */
/*      suspend_ptr                         Pointer to suspend block    */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      Suspension List                                                 */
/*                                                                      */
/************************************************************************/
void  RM_Remove_From_List(struct RM_SUSPENSION_STRUCT **ptr_head_ptr,
       struct RM_SUSPENSION_STRUCT **ptr_tail_ptr,
       struct RM_SUSPENSION_STRUCT *suspend_ptr)
{

    /*  Determine if this suspension block is still linked in.  */
    if ((suspend_ptr -> rm_prev_susp != NU_NULL) || 
            (suspend_ptr -> rm_next_susp != NU_NULL) ||
                                       (suspend_ptr == *ptr_head_ptr))
    {
    
        /* Check the previous pointers.  */
        if (suspend_ptr -> rm_prev_susp != NU_NULL)
        {
        
           /* Link the previous suspension block to the next.  */
           (suspend_ptr -> rm_prev_susp) -> rm_next_susp =  
                                                suspend_ptr -> rm_next_susp;
        }
        else
        {
        
            /* We are deleting the head node, adjust the head pointer.  */
            *ptr_head_ptr =   suspend_ptr -> rm_next_susp;
            
            /* Adjust the head of the list.  */
            if (*ptr_head_ptr != NU_NULL)
                   (*ptr_head_ptr) -> rm_prev_susp =  NU_NULL;
        }
        
        /* Check the next pointers.  */
        if (suspend_ptr -> rm_next_susp != NU_NULL)
        {
        
            /* Link the next suspension block to the previous.  */
            (suspend_ptr -> rm_next_susp) -> rm_prev_susp =
                                                 suspend_ptr -> rm_prev_susp;
        }
        else
        {
        
            /* We are deleting the tail node, adjust the tail pointer.  */
            *ptr_tail_ptr =  suspend_ptr -> rm_prev_susp;

            /* Adjust the tail of the list.  */
            if (*ptr_tail_ptr != NU_NULL)
               (*ptr_tail_ptr) -> rm_next_susp =  NU_NULL;
        }
  
        /* Reset the pointers of the removed suspension block.  */        
        suspend_ptr -> rm_next_susp =    NU_NULL;
        suspend_ptr -> rm_prev_susp =    NU_NULL;
    }           
}                                           /* end  RM_Remove_From_List */



/************************************************************************/
/*                                                                      */
/*  FUNCTION                                "RM_Request_Resource"       */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function requests a resource specified by the input.       */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Service routines that request resources                         */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      SKP_Get_Task_ID                     Get the current task ID     */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      resource_id                         Resource Identification     */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      semaphore                                                       */
/*      return(status)                                                  */
/*                                                                      */
/************************************************************************/
signed int  RM_Request_Resource(signed int resource_id)
{

struct RM_RESOURCE_CONTROL_STRUCT  
                  *RCB_ptr;                 /* Pointer to RCB entry     */
signed int         status;                  /* Status of request        */
    
    /* Point to the resource control block.  */
    RCB_ptr =  &RM_RCB_List[resource_id];
    
    /* See if the resource is free.  */
    if (RCB_ptr -> rm_semaphore == 0)
    {

        /* Yes, the resource is free.  Allocate the resource.  */
        RCB_ptr -> rm_semaphore++;
      
        /* Save the task ID so we can make sure that the same task 
           releases the resource.  */
        RCB_ptr -> rm_task_id =  SKP_Get_Task_ID();

        /* Return a successful status.  */
        status =  NU_SUCCESS;
    }
    else
    {
    
        /* Return an appropriate status to indicate that the resource
           is not available.  */
        status =  NU_NOT_AVAILABLE;
    }
    
    /* Return the status to the caller.  */
    return(status);
}                                           /* end of RM_Request_Resource */



/************************************************************************/
/*                                                                      */
/*  FUNCTION                                "RM_Release_Resource"       */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function releases a resource and allows a task that was    */
/*      previously suspended to run - if it is next in line.            */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Service routines that release resources                         */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      RM_Remove_From_List                 Lift suspension on next task*/
/*      SKP_Ready_Task                      Place the task on ready lst */
/*      SKD_Leave_Task                      Leave the task if necessary */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      resource_id                         Queue identification        */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      return(status)                                                  */
/*                                                                      */
/************************************************************************/
signed int  RM_Release_Resource(signed int resource_id)
{

struct RM_RESOURCE_CONTROL_STRUCT  
                  *RCB_ptr;                 /* Pointer to RCB entry     */
struct RM_SUSPENSION_STRUCT  
                  *suspend_ptr;             /* Suspension pointer       */
signed int         status;                  /* Status of request        */
    
    /* Point to the resource control block.  */
    RCB_ptr =  &RM_RCB_List[resource_id];
    
    /* See if the resource is allocated to the current calling task.  */
    if (RCB_ptr -> rm_task_id == SKP_Get_Task_ID())
    {

        /* Yes the calling task was the one that allocated the resource. */
        status =  NU_SUCCESS;

        /* Decrement the semaphore count and clear the task association.  */
        RCB_ptr -> rm_semaphore--;
        RCB_ptr -> rm_task_id =  NU_SYSTEM;

⌨️ 快捷键说明

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