📄 rm.c
字号:
/* Check for task(s) suspended for the resource. */
if (RCB_ptr -> rm_semaphore > 0)
{
/* There are task(s) waiting for the resource. */
suspend_ptr = RCB_ptr -> rm_wait_head;
/* Set the status of the first waiting task. */
*(suspend_ptr -> rm_return_addr) = NU_SUCCESS;
/* Mark the resource as associated with the suspended task. */
RCB_ptr -> rm_task_id = suspend_ptr -> rm_task_id;
/* Remove the suspend pointer from the suspend list. */
RM_Remove_From_List(&(RCB_ptr -> rm_wait_head),
&(RCB_ptr -> rm_wait_tail),
suspend_ptr);
/* Lift the suspension on the task that was waiting
for the resource and check for necessary context switching. */
if (SKP_Ready_Task(suspend_ptr -> rm_task_id))
{
/* Leave this task temporarily. */
SKD_Leave_Task();
}
}
}
else
{
/* Return a status that indicates the resource was not allocated and
or not allocated to the calling task. */
status = NU_NOT_ALLOCATED;
}
/* Return the status to the caller. */
return(status);
} /* end of RM_Release_Resource */
/************************************************************************/
/* */
/* FUNCTION "RM_Wait_For_Resource" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function suspends the task that need to wait for a */
/* resource. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* Service routines that wait for resources */
/* */
/* ROUTINES CALLED */
/* */
/* RM_Place_On_List Place a suspend block on lst*/
/* RM_Remove_From_List Remove suspended block */
/* SKP_Suspend_Task Suspend the task */
/* */
/* INPUTS */
/* */
/* task_id Task identification */
/* resource_id Resource identification */
/* */
/* OUTPUTS */
/* */
/* return(status) */
/* */
/************************************************************************/
signed int RM_Wait_For_Resource(signed int task_id, signed int resource_id)
{
struct RM_RESOURCE_CONTROL_STRUCT
*RCB_ptr; /* Pointer to RCB entry */
struct RM_SUSPENSION_STRUCT
suspend_block; /* Suspension control block */
signed int status; /* Status of request */
/* Initialize the status variable as NU_RESOURCE_TIMEOUT. */
status = NU_RESOURCE_TIMEOUT;
/* Build the suspension block. */
suspend_block.rm_task_id = task_id;
suspend_block.rm_return_addr = &status;
suspend_block.rm_next_susp = NU_NULL;
suspend_block.rm_prev_susp = NU_NULL;
/* Point to the resource control block. */
RCB_ptr = &RM_RCB_List[resource_id];
/* Increment the semaphore count. */
RCB_ptr -> rm_semaphore++;
/* Place the suspend block on the queue full suspension for associated
resource. */
RM_Place_On_List(&(RCB_ptr -> rm_wait_head),
&(RCB_ptr -> rm_wait_tail),
&suspend_block);
/* Suspend the task. */
SKP_Suspend_Task(task_id, NU_RESOURCE_SUSPEND);
/* Check to see if a timeout occurred. In this case the suspend block
is still part of the list, remove it! */
if (status == NU_RESOURCE_TIMEOUT)
{
/* Remove the suspend block from the list. */
RM_Remove_From_List(&(RCB_ptr -> rm_wait_head),
&(RCB_ptr -> rm_wait_tail),
&suspend_block);
/* Decrement the semaphore count. */
RCB_ptr -> rm_semaphore--;
}
/* Return the status to the caller. */
return(status);
} /* end of RM_Wait_For_Resource */
/************************************************************************/
/* */
/* FUNCTION "RM_Max_Resources" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function returns the total number of system resources. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* Service routines that make resource requests */
/* */
/* ROUTINES CALLED */
/* */
/* None */
/* */
/* INPUTS */
/* */
/* None */
/* */
/* OUTPUTS */
/* */
/* return(RM_Total_Resources) */
/* */
/************************************************************************/
signed int RM_Max_Resources()
{
/* Return the number of resources to the caller. */
return(RM_Total_Resources);
} /* end of RM_Max_Resources */
/************************************************************************/
/* */
/* FUNCTION "RM_Retrieve_Status" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function returns the total number of tasks that have */
/* currently made a request for the resource. This includes the */
/* one task that has the resource. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* Service routines that make resource requests */
/* */
/* ROUTINES CALLED */
/* */
/* None */
/* */
/* INPUTS */
/* */
/* None */
/* */
/* OUTPUTS */
/* */
/* return(RM_RCB_List[resource_id].rm_semaphore) */
/* */
/************************************************************************/
signed int RM_Retrieve_Status(signed int resource_id)
{
/* Return the number of tasks that have requested the resource to
the caller. */
return(RM_RCB_List[resource_id].rm_semaphore);
} /* RM_Retrieve_Status */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -