?? pmc.c
字號:
pool -> pm_tasks_waiting++;
#ifdef INCLUDE_PROVIEW
_RTProf_DumpPartitionPool(RT_PROF_ALLOCATE_PARTITION,pool,RT_PROF_WAIT);
#endif /* INCLUDE_PROVIEW */
/* Setup the suspend block and suspend the calling task. */
suspend_ptr = &suspend_block;
suspend_ptr -> pm_partition_pool = pool;
suspend_ptr -> pm_suspend_link.cs_next = NU_NULL;
suspend_ptr -> pm_suspend_link.cs_previous = NU_NULL;
task = (TC_TCB *) TCT_Current_Thread();
suspend_ptr -> pm_suspended_task = task;
/* Determine if priority or FIFO suspension is associated with the
partition pool. */
if (pool -> pm_fifo_suspend)
{
/* FIFO suspension is required. Link the suspend block into
the list of suspended tasks on this partition pool. */
CSC_Place_On_List((CS_NODE **)
&(pool -> pm_suspension_list),
&(suspend_ptr -> pm_suspend_link));
}
else
{
/* Get the priority of the current thread so the suspend block
can be placed in the appropriate place. */
suspend_ptr -> pm_suspend_link.cs_priority =
TCC_Task_Priority(task);
CSC_Priority_Place_On_List((CS_NODE **)
&(pool -> pm_suspension_list),
&(suspend_ptr -> pm_suspend_link));
}
/* Finally, suspend the calling task. Note that the suspension call
automatically clears the protection on the partition pool. */
TCC_Suspend_Task((NU_TASK *) task, NU_PARTITION_SUSPEND,
PMC_Cleanup, suspend_ptr, suspend);
/* Pickup the return status. */
status = suspend_ptr -> pm_return_status;
*return_pointer = suspend_ptr -> pm_return_pointer;
}
else
{
/* No suspension requested. Simply return an error status. */
status = NU_NO_PARTITION;
#ifdef INCLUDE_PROVIEW
_RTProf_DumpPartitionPool(RT_PROF_ALLOCATE_PARTITION,pool,RT_PROF_FAIL);
#endif /* INCLUDE_PROVIEW */
}
}
/* Release protection of the partition pool. */
TCT_Unprotect();
/* Return to user mode */
NU_USER_MODE();
/* Return the completion status. */
return(status);
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* PMC_Deallocate_Partition */
/* */
/* DESCRIPTION */
/* */
/* This function deallocates a previously allocated partition. If */
/* there is a task waiting for a partition, the partition is simply */
/* given to the waiting task and the waiting task is resumed. */
/* Otherwise, the partition is returned to the partition pool. */
/* */
/* CALLED BY */
/* */
/* Application */
/* PMCE_Deallocate_Partition Error checking shell */
/* */
/* CALLS */
/* */
/* CSC_Remove_From_List Remove from suspend list */
/* [HIC_Make_History_Entry] Make entry in history log */
/* TCC_Resume_Task Resume a suspended task */
/* [TCT_Check_Stack] Stack checking function */
/* TCT_Control_To_System Transfer control to system */
/* TCT_System_Protect Protect partition pool */
/* TCT_Unprotect Release protection */
/* */
/* INPUTS */
/* */
/* partition Pointer to partition memory */
/* */
/* OUTPUTS */
/* */
/* NU_SUCCESS */
/* */
/* HISTORY */
/* */
/* DATE REMARKS */
/* */
/* 03-01-1993 Created initial version 1.0 */
/* 04-19-1993 Verified version 1.0 */
/* 03-01-1994 Added register options, changed */
/* protection logic to reduce */
/* overhead, resulting in */
/* version 1.1 */
/* */
/* 03-18-1994 Verified version 1.1 */
/* */
/*************************************************************************/
STATUS PMC_Deallocate_Partition(VOID *partition)
{
R1 PM_PCB *pool; /* Pool pointer */
R3 PM_SUSPEND *suspend_ptr; /* Pointer to suspend block */
R2 PM_HEADER *header_ptr; /* Pointer to partition hdr */
STATUS preempt; /* Preemption flag */
STATUS status; /* Completion status */
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_DEALLOCATE_PARTITION_ID, (UNSIGNED) partition,
(UNSIGNED) 0, (UNSIGNED) 0);
#endif
/* Initialize the status as successful. */
status = NU_SUCCESS;
/* Pickup the associated pool's pointer. It is inside the header of
each partition. */
header_ptr = (PM_HEADER *) (((BYTE_PTR) partition) - PM_OVERHEAD);
pool = header_ptr -> pm_partition_pool;
/* Protect against simultaneous access to the partition pool. */
TCT_System_Protect();
/* Determine if another task is waiting for a partition from the pool. */
if (pool -> pm_tasks_waiting)
{
/* Yes, another task is waiting for a partition from the pool. */
/* Decrement the number of tasks waiting counter. */
pool -> pm_tasks_waiting--;
#ifdef INCLUDE_PROVIEW
_RTProf_DumpPartitionPool(RT_PROF_DEALLOCATE_PARTITION,pool,RT_PROF_OK);
#endif /* INCLUDE_PROVIEW */
/* Remove the first suspended block from the list. */
suspend_ptr = pool -> pm_suspension_list;
CSC_Remove_From_List((CS_NODE **) &(pool -> pm_suspension_list),
&(suspend_ptr -> pm_suspend_link));
/* Setup the appropriate return value. */
suspend_ptr -> pm_return_status = NU_SUCCESS;
suspend_ptr -> pm_return_pointer = partition;
/* Resume the suspended task. */
preempt =
TCC_Resume_Task((NU_TASK *) suspend_ptr -> pm_suspended_task,
NU_PARTITION_SUSPEND);
/* Determine if a preempt condition is present. */
if (preempt)
/* Transfer control to the system if the resumed task function
detects a preemption condition. */
TCT_Control_To_System();
}
else
{
/* Increment the available partitions counter. */
pool -> pm_available++;
/* Decrement the allocated partitions counter. */
pool -> pm_allocated--;
/* Place the partition back on the available list. */
header_ptr -> pm_next_available = pool -> pm_available_list;
pool -> pm_available_list = header_ptr;
#ifdef INCLUDE_PROVIEW
_RTProf_DumpPartitionPool(RT_PROF_DEALLOCATE_PARTITION,pool,RT_PROF_OK);
#endif /* INCLUDE_PROVIEW */
}
/* Release protection of the partition pool. */
TCT_Unprotect();
/* Return to user mode */
NU_USER_MODE();
/* Return the completion status. */
return(status);
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* PMC_Cleanup */
/* */
/* DESCRIPTION */
/* */
/* This function is responsible for removing a suspension block */
/* from a partition pool. It is not called unless a timeout or */
/* a task terminate is in progress. Note that protection is */
/* already in effect - the same protection at suspension time. */
/* */
/* CALLED BY */
/* */
/* TCC_Timeout Task timeout */
/* TCC_Terminate Task terminate */
/* */
/* CALLS */
/* */
/* CSC_Remove_From_List Remove suspend block from */
/* the suspension list */
/* */
/* INPUTS */
/* */
/* information Pointer to suspend block */
/* */
/* OUTPUTS */
/* */
/* None */
/* */
/* HISTORY */
/* */
/* DATE REMARKS */
/* */
/* 03-01-1993 Created initial version 1.0 */
/* 04-19-1993 Verified version 1.0 */
/* */
/*************************************************************************/
VOID PMC_Cleanup(VOID *information)
{
PM_SUSPEND *suspend_ptr; /* Suspension block pointer */
NU_SUPERV_USER_VARIABLES
/* Switch to supervisor mode */
NU_SUPERVISOR_MODE();
/* Use the information pointer as a suspend pointer. */
suspend_ptr = (PM_SUSPEND *) information;
/* By default, indicate that the service timed-out. It really does not
matter if this function is called from a terminate request since
the task does not resume. */
suspend_ptr -> pm_return_status = NU_TIMEOUT;
suspend_ptr -> pm_return_pointer = NU_NULL;
/* Decrement the number of tasks waiting counter. */
(suspend_ptr -> pm_partition_pool) -> pm_tasks_waiting--;
/* Unlink the suspend block from the suspension list. */
CSC_Remove_From_List((CS_NODE **)
&((suspend_ptr -> pm_partition_pool) -> pm_suspension_list),
&(suspend_ptr -> pm_suspend_link));
/* Return to user mode */
NU_USER_MODE();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -