📄 dmc.c
字号:
/* 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 */
/* */
/*************************************************************************/
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 */
NU_SUPERV_USER_VARIABLES
/* Switch to supervisor mode */
NU_SUPERVISOR_MODE();
/* 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 NU_PROFILE_PLUS
PRF_PLUS_DMC_DELETE_MEMORY_POOL_0
#endif /* NU_PROFILE_PLUS */
/* 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 to user mode */
NU_USER_MODE();
/* 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. */
/* */
/* 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 */
/* */
/*************************************************************************/
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 */
NU_SUPERV_USER_VARIABLES
/* Switch to supervisor mode */
NU_SUPERVISOR_MODE();
/* 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_ALLOCATE_MEMORY_ID, (UNSIGNED) pool,
(UNSIGNED) return_pointer, (UNSIGNED) size);
#endif
/* Initialize the status as successful. */
status = NU_SUCCESS;
/* Adjust the request to a size evenly divisible by the number of bytes
in an UNSIGNED data element. Also, check to make sure it is of the
minimum size. */
if (size < pool -> dm_min_allocation)
/* Change size to the minimum allocation. */
size = pool -> dm_min_allocation;
else
/* Insure that size is a multiple of the UNSIGNED size. */
size =
((size + sizeof(UNSIGNED) - 1)/sizeof(UNSIGNED)) * sizeof(UNSIGNED);
/* Protect against simultaneous access to the memory pool. */
TCT_Protect(&(pool -> dm_protect));
/* Search the memory list for the first available block of memory that
satisfies the request. Note that blocks are merged during the
deallocation function. */
memory_ptr = pool -> dm_search_ptr;
do
{
/* Determine if the block is free and if it can satisfy the request. */
if (memory_ptr -> dm_memory_free)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -