📄 allocation.c
字号:
/************************************************** * * allocation.c * * CVS ID: $Id: allocation.c,v 1.5 2006/10/27 12:52:55 belardi Exp $ * Author: Leos Longauer [LL] - STM * Date: $Date: 2006/10/27 12:52:55 $ * Revision: $Revision: 1.5 $ * * Description: * * Memory allocation. * *************************************************** * * COPYRIGHT (C) ST Microelectronics 2006 * All Rights Reserved * *************************************************** * * STM CVS Log: * * $Log: allocation.c,v $ * Revision 1.5 2006/10/27 12:52:55 belardi * Added #include to remove compiler warning * * Revision 1.4 2006/09/18 09:55:23 belardi * Corrected CVS keyword usage * * Revision 1.3 2006/09/18 09:24:43 belardi * Added Log CVS keyword into file header * * ***************************************************/#include <string.h>#include <stdio.h>#include "configuration.h"#include "debug.h"#include "gendef.h"#include "osal.h"#include "allocation.h"static sint32 fast_malloc_items_allocated = 0;#if (FAST_MALLOC_DEBUG != 0)#include"debug.h"typedef struct _FastAllocDBG_{ uint32 dbg_null_malloc; uint32 dbg_null_free; uint32 dbg_wrong_deallocated;} _FastAllocDBG;_FastAllocDBG FastAllocDBG;//FastAllocDBG.dbg_null_malloc = 0;//FastAllocDBG.dbg_null_free = 0;//FastAllocDBG.dbg_wrong_deallocated = 0;#endifvoid* MALLOC(size_t requested){ void* Memory = NULL; if (requested == 0) {#if (FAST_MALLOC_DEBUG != 0) DBG_PRINTF("allocation: *W - Zero argument to MALLOC\r\n");#endif /*FAST_MALLOC_DEBUG*/ return Memory; } Memory = memory_allocate(internal_partition, requested); if (Memory != NULL) fast_malloc_items_allocated++; else { DBG_PRINTF("allocation: *E - Out of memory\r\n");#if (FAST_MALLOC_DEBUG != 0) FastAllocDBG.dbg_null_malloc++;#endif /*FAST_MALLOC_DEBUG*/ } return Memory;}void FREE(void* block){ if (block != NULL) { memory_deallocate(internal_partition, block); fast_malloc_items_allocated--; }#if (FAST_MALLOC_DEBUG != 0) else { DBG_PRINTF("allocation: *W - NULL FREE\r\n"); FastAllocDBG.dbg_null_free++; }#endif /*FAST_MALLOC_DEBUG*/ RESTORE_MALLOC_BUFFER_SIZE();}t_bool RESTORE_MALLOC_BUFFER_SIZE(void){ /* memory should be 'free' -> reset allocation pointer */ if (fast_malloc_items_allocated == 0) { //semaphore_wait (&partition->partition_lock); internal_partition->partition_ffree = internal_partition->partition_fbase; //semaphore_signal (&partition->partition_lock); return TRUE; } /* free() called more times than malloc() */ if (fast_malloc_items_allocated < 0) { fast_malloc_items_allocated = 0; //semaphore_wait (&partition->partition_lock); internal_partition->partition_ffree = internal_partition->partition_fbase; //semaphore_signal (&partition->partition_lock); DBG_PRINTF("allocation: *E - Memory deallocation fatal error!\r\n");#if (FAST_MALLOC_DEBUG != 0) FastAllocDBG.dbg_wrong_deallocated++; FastAllocDBG.dbg_null_malloc = 0; FastAllocDBG.dbg_null_free = 0;#endif /*FAST_MALLOC_DEBUG*/ } return TRUE; /* restoring posponed */}void INIT_FAST_MALLOC(void){ if(fast_malloc_items_allocated) { //semaphore_wait (&partition->partition_lock); internal_partition->partition_ffree = internal_partition->partition_fbase; //semaphore_signal (&partition->partition_lock); fast_malloc_items_allocated = 0; DBG_PRINTF("allocation: Memory reinitialized to: 0x%4x", internal_partition->partition_ffree); }#if (FAST_MALLOC_DEBUG != 0) else { DBG_PRINTF("allocation: no reinitialization needed") }#endif /*FAST_MALLOC_DEBUG*/}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -