461 #ifndef LEGATO_MEM_INCLUDE_GUARD 462 #define LEGATO_MEM_INCLUDE_GUARD 466 #ifndef LE_COMPONENT_NAME 467 # define LE_COMPONENT_NAME 489 #define LE_MEM_LIMIT_MAX_MEM_POOL_NAME_BYTES 32 499 typedef struct le_mem_Pool
503 #if LE_CONFIG_MEM_POOL_STATS 508 uint64_t numAllocations;
509 size_t maxNumBlocksUsed;
512 #if LE_CONFIG_MEM_POOLS 519 size_t numBlocksInUse;
522 #if LE_CONFIG_MEM_TRACE 524 le_log_TraceRef_t memTrace;
529 #if LE_CONFIG_MEM_POOL_NAMES_ENABLED 561 #if LE_CONFIG_MEM_TRACE 567 le_mem_PoolRef_t _le_mem_GetBlockPool
572 typedef void* (*_le_mem_AllocFunc_t)(le_mem_PoolRef_t pool);
579 void* _le_mem_AllocTracer
581 le_mem_PoolRef_t pool,
582 _le_mem_AllocFunc_t funcPtr,
583 const char* poolFunction,
585 const char* callingfunction,
595 void* _le_mem_VarAllocTracer
597 le_mem_PoolRef_t pool,
599 _le_mem_AllocFunc_t funcPtr,
600 const char* poolFunction,
602 const char* callingfunction,
614 le_mem_PoolRef_t pool,
616 const char* callingfunction,
618 const char* poolFunction,
632 le_mem_PoolRef_t _le_mem_InitStaticPool
634 const char* componentName,
645 #if LE_CONFIG_MEM_POOL_NAMES_ENABLED 653 le_mem_PoolRef_t _le_mem_CreatePool
655 const char* componentName,
690 le_mem_PoolRef_t _le_mem_CreatePool
715 return _le_mem_CreatePool(objSize);
726 #define LE_MEM_POOL_WORDS(numBlocks, objSize) \ 727 ((numBlocks)*(((sizeof(le_mem_Pool_t*) + sizeof(size_t)) + \ 728 (((objSize)<sizeof(le_sls_Link_t))?sizeof(le_sls_Link_t):(objSize))+ \ 729 sizeof(uint32_t)*LE_CONFIG_NUM_GUARD_BAND_WORDS*2+ \ 730 sizeof(size_t) - 1) / sizeof(size_t))) 744 #define LE_MEM_BLOCKS(name, def) (LE_DEFAULT(CAT(_mem_, CAT(name, _POOL_SIZE)), (def))) 764 #if LE_CONFIG_MEM_POOLS 765 # define LE_MEM_DEFINE_STATIC_POOL(name, numBlocks, objSize) \ 766 static le_mem_Pool_t _mem_##name##Pool; \ 767 static size_t _mem_##name##Data[LE_MEM_POOL_WORDS(LE_MEM_BLOCKS(name, numBlocks), objSize)] 769 # define LE_MEM_DEFINE_STATIC_POOL(name, numBlocks, objSize) \ 770 static le_mem_Pool_t _mem_##name##Pool 796 #if LE_CONFIG_MEM_POOLS 797 # define LE_MEM_DEFINE_STATIC_POOL_IN_SECTION(name, numBlocks, objSize, sectionName) \ 798 static le_mem_Pool_t _mem_##name##Pool __attribute__((section(sectionName))); \ 799 static size_t _mem_##name##Data[LE_MEM_POOL_WORDS( \ 800 LE_MEM_BLOCKS(name, numBlocks), objSize)] __attribute__((section(sectionName))) 802 # define LE_MEM_DEFINE_STATIC_POOL_IN_SECTION(name, numBlocks, objSize, sectionName) \ 803 static le_mem_Pool_t _mem_##name##Pool __attribute__((section(sectionName))); 822 #if LE_CONFIG_MEM_POOLS 823 # define le_mem_InitStaticPool(name, numBlocks, objSize) \ 824 (inline_static_assert( \ 825 sizeof(_mem_##name##Data) == \ 826 sizeof(size_t[LE_MEM_POOL_WORDS(LE_MEM_BLOCKS(name, numBlocks), objSize)]), \ 827 "initial pool size does not match definition"), \ 828 _le_mem_InitStaticPool(STRINGIZE(LE_COMPONENT_NAME), #name, \ 829 LE_MEM_BLOCKS(name, numBlocks), (objSize), &_mem_##name##Pool, _mem_##name##Data)) 831 # define le_mem_InitStaticPool(name, numBlocks, objSize) \ 832 _le_mem_InitStaticPool(STRINGIZE(LE_COMPONENT_NAME), #name, \ 833 LE_MEM_BLOCKS(name, numBlocks), (objSize), &_mem_##name##Pool, NULL) 848 le_mem_PoolRef_t pool,
854 #if !LE_CONFIG_MEM_TRACE 866 le_mem_PoolRef_t pool
869 void* _le_mem_TryAlloc(le_mem_PoolRef_t pool);
873 # define le_mem_TryAlloc(pool) \ 874 _le_mem_AllocTracer(pool, \ 877 STRINGIZE(LE_FILENAME), \ 884 #if !LE_CONFIG_MEM_TRACE 898 le_mem_PoolRef_t pool
901 void* _le_mem_AssertAlloc(le_mem_PoolRef_t pool);
905 # define le_mem_AssertAlloc(pool) \ 906 _le_mem_AllocTracer(pool, \ 907 _le_mem_AssertAlloc, \ 908 "le_mem_AssertAlloc", \ 909 STRINGIZE(LE_FILENAME), \ 915 #if !LE_CONFIG_MEM_TRACE 929 le_mem_PoolRef_t pool
932 void* _le_mem_ForceAlloc(le_mem_PoolRef_t pool);
936 # define le_mem_ForceAlloc(pool) \ 937 _le_mem_AllocTracer(pool, \ 938 _le_mem_ForceAlloc, \ 939 "le_mem_ForceAlloc", \ 940 STRINGIZE(LE_FILENAME), \ 946 #if !LE_CONFIG_MEM_TRACE 958 le_mem_PoolRef_t pool,
962 void* _le_mem_TryVarAlloc(le_mem_PoolRef_t pool,
size_t size);
966 # define le_mem_TryVarAlloc(pool, size) \ 967 _le_mem_VarAllocTracer(pool, \ 969 _le_mem_TryVarAlloc, \ 970 "le_mem_TryVarAlloc", \ 971 STRINGIZE(LE_FILENAME), \ 978 #if !LE_CONFIG_MEM_TRACE 992 le_mem_PoolRef_t pool,
996 void* _le_mem_AssertVarAlloc(le_mem_PoolRef_t pool,
size_t size);
1000 # define le_mem_AssertVarAlloc(pool, size) \ 1001 _le_mem_VarAllocTracer(pool, \ 1003 _le_mem_AssertVarAlloc, \ 1004 "le_mem_AssertVarAlloc", \ 1005 STRINGIZE(LE_FILENAME), \ 1011 #if !LE_CONFIG_MEM_TRACE 1025 le_mem_PoolRef_t pool,
1029 void* _le_mem_ForceVarAlloc(le_mem_PoolRef_t pool,
size_t size);
1033 # define le_mem_ForceVarAlloc(pool, size) \ 1034 _le_mem_VarAllocTracer(pool, \ 1036 _le_mem_ForceVarAlloc, \ 1037 "le_mem_ForceVarAlloc", \ 1038 STRINGIZE(LE_FILENAME), \ 1055 #if LE_CONFIG_MEM_ALLOC_FORCE 1056 # define le_mem_Alloc(pool) le_mem_ForceAlloc(pool) 1057 #elif LE_CONFIG_MEM_ALLOC_ASSERT 1058 # define le_mem_Alloc(pool) le_mem_AssertAlloc(pool) 1060 # error "No supported allocation scheme selected!" 1076 #if LE_CONFIG_MEM_ALLOC_FORCE 1077 # define le_mem_VarAlloc(pool, size) le_mem_ForceVarAlloc((pool), (size)) 1078 #elif LE_CONFIG_MEM_ALLOC_ASSERT 1079 # define le_mem_VarAlloc(pool, size) le_mem_AssertVarAlloc((pool), (size)) 1081 # error "No supported allocation scheme selected!" 1097 le_mem_PoolRef_t pool,
1103 #if !LE_CONFIG_MEM_TRACE 1124 void _le_mem_Release(
void* objPtr);
1128 # define le_mem_Release(objPtr) \ 1129 _le_mem_Trace(_le_mem_GetBlockPool(objPtr), \ 1130 STRINGIZE(LE_FILENAME), \ 1135 _le_mem_Release(objPtr); 1139 #if !LE_CONFIG_MEM_TRACE 1155 void _le_mem_AddRef(
void* objPtr);
1159 # define le_mem_AddRef(objPtr) \ 1160 _le_mem_Trace(_le_mem_GetBlockPool(objPtr), \ 1161 STRINGIZE(LE_FILENAME), \ 1166 _le_mem_AddRef(objPtr); 1214 le_mem_PoolRef_t pool,
1229 le_mem_PoolRef_t pool,
1244 le_mem_PoolRef_t pool
1262 le_mem_PoolRef_t pool,
1279 le_mem_PoolRef_t pool
1294 le_mem_PoolRef_t pool
1308 le_mem_PoolRef_t pool
1322 le_mem_PoolRef_t pool
1326 #if LE_CONFIG_MEM_POOL_NAMES_ENABLED 1334 le_mem_PoolRef_t _le_mem_FindPool
1336 const char* componentName,
1374 #if LE_CONFIG_MEM_POOL_NAMES_ENABLED 1382 le_mem_PoolRef_t _le_mem_CreateSubPool
1384 le_mem_PoolRef_t superPool,
1385 const char* componentName,
1403 le_mem_PoolRef_t superPool,
1419 le_mem_PoolRef_t _le_mem_CreateSubPool
1421 le_mem_PoolRef_t superPool,
1437 le_mem_PoolRef_t superPool,
1443 return _le_mem_CreateSubPool(superPool, numObjects);
1448 #if LE_CONFIG_MEM_POOL_NAMES_ENABLED 1456 le_mem_PoolRef_t _le_mem_CreateReducedPool
1458 le_mem_PoolRef_t superPool,
1459 const char* componentName,
1478 le_mem_PoolRef_t superPool,
1496 le_mem_PoolRef_t _le_mem_CreateReducedPool
1498 le_mem_PoolRef_t superPool,
1516 le_mem_PoolRef_t superPool,
1524 return _le_mem_CreateReducedPool(superPool, numObjects, objSize);
1541 le_mem_PoolRef_t subPool
1557 void **freeStartPtr,
1590 le_mem_PoolRef_t poolRef,
1594 #endif // LEGATO_MEM_INCLUDE_GUARD void * le_mem_AssertVarAlloc(le_mem_PoolRef_t pool, size_t size)
size_t le_mem_GetObjectSize(le_mem_PoolRef_t pool)
static le_mem_PoolRef_t le_mem_CreateReducedPool(le_mem_PoolRef_t superPool, const char *name, size_t numObjects, size_t objSize)
Definition: le_mem.h:1477
size_t blockSize
Number of bytes in a block, including all overhead.
Definition: le_mem.h:517
uint64_t numAllocs
Number of times an object has been allocated from this pool.
Definition: le_mem.h:555
char * le_mem_StrDup(le_mem_PoolRef_t poolRef, const char *srcStr)
LE_DECLARE_INLINE le_mem_PoolRef_t le_mem_CreatePool(const char *name, size_t objSize)
Definition: le_mem.h:709
Definition: le_singlyLinkedList.h:201
size_t numBlocksInUse
Number of currently allocated blocks.
Definition: le_mem.h:552
size_t numOverflows
Number of times le_mem_ForceAlloc() had to expand the pool.
Definition: le_mem.h:554
Definition: le_doublyLinkedList.h:200
size_t le_mem_GetBlockSize(void *objPtr)
void(* le_mem_Destructor_t)(void *objPtr)
Definition: le_mem.h:484
#define STRINGIZE(x)
Definition: le_basics.h:231
le_dls_Link_t poolLink
This pool's link in the list of memory pools.
Definition: le_mem.h:501
size_t maxNumBlocksUsed
Maximum number of allocated blocks at any one time.
Definition: le_mem.h:553
struct le_mem_Pool * superPoolPtr
Definition: le_mem.h:502
void * le_mem_TryAlloc(le_mem_PoolRef_t pool)
void * le_mem_TryVarAlloc(le_mem_PoolRef_t pool, size_t size)
size_t numFree
Number of free objects currently available in this pool.
Definition: le_mem.h:556
void le_mem_GetStats(le_mem_PoolRef_t pool, le_mem_PoolStats_t *statsPtr)
void * le_mem_AssertAlloc(le_mem_PoolRef_t pool)
void le_mem_Hibernate(void **freeStartPtr, void **freeEndPtr)
size_t le_mem_GetRefCount(void *objPtr)
size_t le_mem_GetObjectFullSize(le_mem_PoolRef_t pool)
void * le_mem_ForceVarAlloc(le_mem_PoolRef_t pool, size_t size)
#define LE_DECLARE_INLINE
Definition: le_basics.h:330
void le_mem_Release(void *objPtr)
bool le_mem_IsSubPool(le_mem_PoolRef_t pool)
void * le_mem_ForceAlloc(le_mem_PoolRef_t pool)
static le_mem_PoolRef_t le_mem_FindPool(const char *name)
Definition: le_mem.h:1349
size_t le_mem_GetObjectCount(le_mem_PoolRef_t pool)
void le_mem_SetDestructor(le_mem_PoolRef_t pool, le_mem_Destructor_t destructor)
struct le_mem_Pool * le_mem_PoolRef_t
Definition: le_mem.h:542
void le_mem_SetNumObjsToForce(le_mem_PoolRef_t pool, size_t numObjects)
le_result_t le_mem_GetName(le_mem_PoolRef_t pool, char *namePtr, size_t bufSize)
size_t numBlocksToForce
Definition: le_mem.h:521
void le_mem_DeleteSubPool(le_mem_PoolRef_t subPool)
void le_mem_AddRef(void *objPtr)
static le_mem_PoolRef_t le_mem_CreateSubPool(le_mem_PoolRef_t superPool, const char *name, size_t numObjects)
Definition: le_mem.h:1402
le_result_t
Definition: le_basics.h:45
#define LE_MEM_LIMIT_MAX_MEM_POOL_NAME_BYTES
Definition: le_mem.h:489
#define LE_COMPONENT_NAME
Definition: le_mem.h:467
le_mem_PoolRef_t le_mem_ExpandPool(le_mem_PoolRef_t pool, size_t numObjects)
size_t userDataSize
Size of the object requested by the client in bytes.
Definition: le_mem.h:516
void le_mem_ResetStats(le_mem_PoolRef_t pool)
size_t totalBlocks
Definition: le_mem.h:518
le_mem_Destructor_t destructor
The destructor for objects in this pool.
Definition: le_mem.h:528