📄 dmc.c
字号:
/*************************************************************************/
/* */
/* Copyright (c) 1993-2001 Accelerated Technology, Inc. */
/* */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the */
/* subject matter of this material. All manufacturing, reproduction, */
/* use, and sales rights pertaining to this subject matter are governed */
/* by the license agreement. The recipient of this software implicitly */
/* accepts the terms of the license. */
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* FILE NAME VERSION */
/* */
/* dmc.c PLUS 1.13 */
/* */
/* COMPONENT */
/* */
/* DM - Dynamic Memory Management */
/* */
/* DESCRIPTION */
/* */
/* This file contains the core routines for the Dynamic Memory */
/* Management component. */
/* */
/* AUTHOR */
/* */
/* Accelerated Technology, Inc. */
/* */
/* DATA STRUCTURES */
/* */
/* None */
/* */
/* FUNCTIONS */
/* */
/* DMC_Create_Memory_Pool Create a dynamic memory pool */
/* DMC_Delete_Memory_Pool Delete a dynamic memory pool */
/* DMC_Allocate_Memory Allocate a memory block from */
/* a dynamic memory pool */
/* DMC_Deallocate_Memory Deallocate a memory block */
/* from a dynamic memory pool */
/* DMC_Cleanup Cleanup on timeout or a */
/* terminate condition */
/* */
/* DEPENDENCIES */
/* */
/* cs_extr.h Common Service functions */
/* tc_extr.h Thread Control functions */
/* dm_extr.h Partition functions */
/* hi_extr.h History functions */
/* */
/* HISTORY */
/* */
/* DATE REMARKS */
/* */
/* 03-01-1993 Created initial version 1.0 */
/* 04-19-1993 Verified version 1.0 */
/* 08-09-1993 Corrected pointer retrieval */
/* loop, resulting in version 1.0a */
/* 08-09-1993 Verified version 1.0a */
/* 03-01-1994 Moved non-core functions into */
/* supplemental files, 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 */
/* 04-17-1996 updated to version 1.2 */
/* 03-24-1998 Released version 1.3. */
/* */
/*************************************************************************/
#define NU_SOURCE_FILE
#include "cs_extr.h" /* Common service functions */
#include "tc_extr.h" /* Thread control functions */
#include "dm_extr.h" /* Dynamic memory functions */
#include "hi_extr.h" /* History functions */
/* Define external inner-component global data references. */
extern CS_NODE *DMD_Created_Pools_List;
extern UNSIGNED DMD_Total_Pools;
extern TC_PROTECT DMD_List_Protect;
/* Define internal component function prototypes. */
VOID DMC_Cleanup(VOID *information);
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* DMC_Create_Memory_Pool */
/* */
/* DESCRIPTION */
/* */
/* This function creates a dynamic memory pool and then places it */
/* on the list of created dynamic memory pools. */
/* */
/* AUTHOR */
/* */
/* Accelerated Technology, Inc. */
/* */
/* CALLED BY */
/* */
/* Application */
/* DMCE_Create_Memory_Pool Error checking shell */
/* */
/* CALLS */
/* */
/* CSC_Place_On_List Add node to linked-list */
/* [HIC_Make_History_Entry] Make entry in history log */
/* [TCT_Check_Stack] Stack checking function */
/* TCT_Protect Data structure protect */
/* TCT_Unprotect Un-protect data structure */
/* */
/* INPUTS */
/* */
/* pool_ptr Memory pool control block */
/* pointer */
/* name Memory pool name */
/* start_address Starting address of the pool */
/* pool_size Number of bytes in the pool */
/* min_allocation Minimum allocation size */
/* suspend_type Suspension type */
/* */
/* 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, */
/* resulting in version 1.1 */
/* */
/* 03-18-1994 Verified version 1.1 */
/* */
/*************************************************************************/
STATUS DMC_Create_Memory_Pool(NU_MEMORY_POOL *pool_ptr, CHAR *name,
VOID *start_address, UNSIGNED pool_size,
UNSIGNED min_allocation, OPTION suspend_type)
{
R1 DM_PCB *pool; /* Pool control block ptr */
INT i; /* Working index variable */
DM_HEADER *header_ptr; /* Partition block header ptr*/
/* 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_CREATE_MEMORY_POOL_ID, (UNSIGNED) pool,
(UNSIGNED) start_address, (UNSIGNED) pool_size);
#endif
/* First, clear the partition pool ID just in case it is an old
pool control block. */
pool -> dm_id = 0;
/* Fill in the partition pool name. */
for (i = 0; i < NU_MAX_NAME; i++)
pool -> dm_name[i] = name[i];
/* Convert the pool's size into something that is evenly divisible by
the sizeof an UNSIGNED data element. */
pool_size = (pool_size/sizeof(UNSIGNED)) * sizeof(UNSIGNED);
/* Save the starting address and size parameters in the dynamic memory
control block. */
pool -> dm_start_address = start_address;
pool -> dm_pool_size = pool_size;
pool -> dm_min_allocation =
((min_allocation + sizeof(UNSIGNED) - 1)/sizeof(UNSIGNED)) *
sizeof(UNSIGNED);
/* Setup the dynamic memory pool suspension type. */
if (suspend_type == NU_FIFO)
/* FIFO suspension is selected, setup the flag accordingly. */
pool -> dm_fifo_suspend = NU_TRUE;
else
/* Priority suspension is selected. */
pool -> dm_fifo_suspend = NU_FALSE;
/* Clear the suspension list pointer. */
pool -> dm_suspension_list = NU_NULL;
/* Clear the number of tasks waiting on the dynamic memory pool. */
pool -> dm_tasks_waiting = 0;
/* Initialize link pointers. */
pool -> dm_created.cs_previous = NU_NULL;
pool -> dm_created.cs_next = NU_NULL;
/* Build a single block that has all of the memory. */
header_ptr = (DM_HEADER *) start_address;
/* Initialize the memory parameters. */
pool -> dm_available = pool_size - (2 * DM_OVERHEAD);
pool -> dm_memory_list = header_ptr;
pool -> dm_search_ptr = header_ptr;
/* Build the block header. */
header_ptr -> dm_memory_pool = pool;
header_ptr -> dm_memory_free = NU_TRUE;
header_ptr -> dm_next_memory = (DM_HEADER *)
(((BYTE_PTR) header_ptr) + pool -> dm_available + DM_OVERHEAD);
header_ptr -> dm_previous_memory = header_ptr -> dm_next_memory;
/* Build the small trailer block that prevents block merging when the
pool wraps around. Note that the list is circular so searching can
wrap across the physical end of the memory pool. */
header_ptr = header_ptr -> dm_next_memory;
header_ptr -> dm_next_memory = (DM_HEADER *) start_address;
header_ptr -> dm_previous_memory = (DM_HEADER *) start_address;
header_ptr -> dm_memory_pool = pool;
header_ptr -> dm_memory_free = NU_FALSE;
/* Initialize the protection structure. */
pool -> dm_protect.tc_tcb_pointer = NU_NULL;
/* Protect against access to the list of created memory pools. */
TCT_Protect(&DMD_List_Protect);
/* At this point the dynamic memory pool is completely built. The ID can
now be set and it can be linked into the created dynamic memory
pool list. */
pool -> dm_id = DM_DYNAMIC_ID;
/* Link the memory pool into the list of created memory pools and
increment the total number of pools in the system. */
CSC_Place_On_List(&DMD_Created_Pools_List, &(pool -> dm_created));
DMD_Total_Pools++;
#ifdef INCLUDE_PROVIEW
_RTProf_DumpMemoryPool(RT_PROF_CREATE_MEMORY_POOL,pool,RT_PROF_OK);
#endif /*INCLUDE_PROVIEW*/
/* Release protection against access to the list of created memory
pools. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -