📄 dmc.c
字号:
TCT_Unprotect();
/* Return successful completion. */
return(NU_SUCCESS);
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* DMC_Delete_Memory_Pool */
/* */
/* DESCRIPTION */
/* */
/* This function deletes a dynamic memory pool and removes it from */
/* the list of created memory pools. All tasks suspended on the */
/* memory pool are resumed with the appropriate error status. */
/* Note that this function does not free any memory associated with */
/* either the pool area or the pool control block. */
/* */
/* AUTHOR */
/* */
/* Accelerated Technology, Inc. */
/* */
/* CALLED BY */
/* */
/* Application */
/* DMCE_Delete_Memory_Pool Error checking shell */
/* */
/* CALLS */
/* */
/* CSC_Remove_From_List Remove node from 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_Protect Protect created list */
/* TCT_Set_Current_Protect Modify current protection */
/* TCT_System_Protect Setup system protection */
/* TCT_System_Unprotect Release system protection */
/* TCT_Unprotect Release protection */
/* */
/* INPUTS */
/* */
/* pool_ptr Memory pool control block */
/* pointer */
/* */
/* OUTPUTS */
/* */
/* NU_SUCCESS */
/* */
/* HISTORY */
/* */
/* DATE REMARKS */
/* */
/* 03-01-1993 Created initial version 1.0 */
/* 04-19-1993 Verified version 1.0 */
/* 03-01-1994 Changed function interfaces to */
/* match those in prototype, */
/* added register options, changed */
/* protection logic to reduce */
/* overhead, resulting in */
/* version 1.1 */
/* */
/* 03-18-1994 Verified version 1.1 */
/* */
/*************************************************************************/
STATUS DMC_Delete_Memory_Pool(NU_MEMORY_POOL *pool_ptr)
{
R1 DM_PCB *pool; /* Pool control block ptr */
DM_SUSPEND *suspend_ptr; /* Suspend block pointer */
DM_SUSPEND *next_ptr; /* Next suspend block */
STATUS preempt; /* Status for resume call */
/* Move input pool pointer into internal pointer. */
pool = (DM_PCB *) pool_ptr;
#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_DELETE_MEMORY_POOL_ID, (UNSIGNED) pool,
(UNSIGNED) 0, (UNSIGNED) 0);
#endif
/* Protect against simultaneous access to the memory pool. */
TCT_Protect(&(pool -> dm_protect));
#ifdef INCLUDE_PROVIEW
_RTProf_DumpMemoryPool(RT_PROF_DELETE_MEMORY_POOL,pool,RT_PROF_OK);
#endif /*INCLUDE_PROVIEW*/
/* Clear the memory pool ID. */
pool -> dm_id = 0;
/* Release protection. */
TCT_Unprotect();
/* Protect against access to the list of created memory pools. */
TCT_Protect(&DMD_List_Protect);
/* Remove the memory pool from the list of created memory pools. */
CSC_Remove_From_List(&DMD_Created_Pools_List, &(pool -> dm_created));
/* Decrement the total number of created memory pools. */
DMD_Total_Pools--;
/* Pickup the suspended task pointer list. */
suspend_ptr = pool -> dm_suspension_list;
/* Walk the chain task(s) currently suspended on the memory pool. */
preempt = 0;
while (suspend_ptr)
{
/* Protect against system access. */
TCT_System_Protect();
/* Resume the suspended task. Insure that the status returned is
NU_POOL_DELETED. */
suspend_ptr -> dm_return_pointer = NU_NULL;
suspend_ptr -> dm_return_status = NU_POOL_DELETED;
/* Point to the next suspend structure in the link. */
next_ptr = (DM_SUSPEND *) (suspend_ptr -> dm_suspend_link.cs_next);
/* Resume the specified task. */
preempt = preempt |
TCC_Resume_Task((NU_TASK *) suspend_ptr -> dm_suspended_task,
NU_MEMORY_SUSPEND);
/* Determine if the next is the same as the current pointer. */
if (next_ptr == pool -> dm_suspension_list)
/* Clear the suspension pointer to signal the end of the list
traversal. */
suspend_ptr = NU_NULL;
else
/* Move the next pointer into the suspend block pointer. */
suspend_ptr = next_ptr;
/* Modify current protection. */
TCT_Set_Current_Protect(&DMD_List_Protect);
/* Clear the system protection. */
TCT_System_Unprotect();
}
/* Determine if preemption needs to occur. */
if (preempt)
/* Transfer control to system to facilitate preemption. */
TCT_Control_To_System();
/* Release protection against access to the list of created memory
pools. */
TCT_Unprotect();
/* Return a successful completion. */
return(NU_SUCCESS);
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* DMC_Allocate_Memory */
/* */
/* DESCRIPTION */
/* */
/* This function allocates memory from the specified dynamic memory */
/* pool. If dynamic memory is currently available, this function */
/* is completed immediately. Otherwise, if there is not enough */
/* memory currently available, task suspension is possible. */
/* */
/* AUTHOR */
/* */
/* Accelerated Technology, Inc. */
/* */
/* CALLED BY */
/* */
/* Application */
/* DMCE_Allocate_Memory Error checking shell */
/* */
/* CALLS */
/* */
/* CSC_Place_On_List Place on suspend list */
/* [HIC_Make_History_Entry] Make entry in history log */
/* TCC_Suspend_Task Suspend calling task */
/* TCC_Task_Priority Pickup task priority */
/* [TCT_Check_Stack] Stack checking function */
/* TCT_Current_Thread Pickup current thread pointer*/
/* TCT_Protect Protect memory pool */
/* TCT_Set_Suspend_Protect Save suspend protection */
/* TCT_System_Protect Protect system structures */
/* TCT_Unprotect Release protection */
/* TCT_Unprotect_Specific Release specific protection */
/* */
/* INPUTS */
/* */
/* pool_ptr Memory pool pointer */
/* return_pointer Pointer to the destination */
/* memory pointer */
/* size Number of bytes requested */
/* suspend Suspension option if full */
/* */
/* OUTPUTS */
/* */
/* NU_SUCCESS If service is successful */
/* NU_NO_MEMORY Memory not available */
/* NU_TIMEOUT If timeout on service */
/* NU_POOL_DELETED If memory pool deleted */
/* during suspension */
/* */
/* HISTORY */
/* */
/* DATE REMARKS */
/* */
/* 03-01-1993 Created initial version 1.0 */
/* 04-19-1993 Verified version 1.0 */
/* 03-01-1994 Changed function interfaces to */
/* match those in prototype, */
/* added register options, changed */
/* protection logic to reduce */
/* overhead, resulting in */
/* version 1.1 */
/* */
/* 03-18-1994 Verified version 1.1 */
/* */
/*************************************************************************/
STATUS DMC_Allocate_Memory(NU_MEMORY_POOL *pool_ptr, VOID **return_pointer,
UNSIGNED size, UNSIGNED suspend)
{
R1 DM_PCB *pool; /* Pool control block ptr */
R2 DM_SUSPEND *suspend_ptr; /* Pointer to suspend block */
DM_SUSPEND suspend_block; /* Allocate suspension block */
R4 DM_HEADER *memory_ptr; /* Pointer to memory */
R3 DM_HEADER *new_ptr; /* New split block pointer */
UNSIGNED free_size; /* Size of block found */
TC_TCB *task; /* Task pointer */
STATUS status; /* Completion status */
/* Move input pool pointer into internal pointer. */
pool = (DM_PCB *) pool_ptr;
#ifdef NU_ENABLE_STACK_CHECK
/* Call stack checking function to check for an overflow condition. */
TCT_Check_Stack();
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -