SYS/BIOS  7.00
HeapMem.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Texas Instruments Incorporated - https://www.ti.com
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
115 /*
116  * ======== HeapMem.h ========
117  */
118 
119 #ifndef ti_sysbios_heaps_HeapMem__include
120 #define ti_sysbios_heaps_HeapMem__include
121 
122 #include <stdbool.h>
123 #include <stddef.h>
124 #include <stdint.h>
125 
126 #include <ti/sysbios/knl/Queue.h>
127 
131 
133 /* BIOS 6.x compatibility, use -Dxdc_std__include to disable */
134 #include <xdc/std.h>
135 
136 #define ti_sysbios_heaps_HeapMem_long_names
137 #include "HeapMem_defs.h"
140 #ifdef __cplusplus
141 extern "C" {
142 #endif
143 
144 #define HeapMem_reqAlign sizeof(HeapMem_Header)
145 
149 #define HeapMem_A_align "Requested align is not a power of 2"
150 
154 #define HeapMem_A_heapSize "Requested heap size is too small"
155 
168 #define HeapMem_A_invalidFree "Heap-block free operations must not leave the heap in an invalid state"
169 
177 #define HeapMem_A_zeroBlock "Cannot allocate size 0"
178 
182 #define HeapMem_E_memory "out of memory: handle = 0x%x, size=%u"
183 
187 typedef struct {
198  void * buf;
204  size_t size;
206 
208 typedef struct HeapMem_Header {
209  struct HeapMem_Header *next;
215  size_t size;
216 } HeapMem_Header;
219 typedef struct {
254  void * buf;
260  size_t size;
262 
264 typedef struct {
265  IHeap_Object iheap;
266  Queue_Elem objElem;
285  size_t align;
296  char *buf;
297  HeapMem_Header head;
321  size_t minBlockAlign;
322 } HeapMem_Struct, *HeapMem_Handle;
325 typedef HeapMem_Struct HeapMem_Object;
326 
328 typedef struct {
329  Queue_Struct objQ;
330 } HeapMem_Module_State;
340 #define ti_sysbios_heaps_HeapMem_Handle_upCast(handle) ((IHeap_Handle)(handle))
341 
375 extern void * HeapMem_alloc(HeapMem_Handle heap, size_t size, size_t align, Error_Block *eb);
376 
390 extern void HeapMem_free(HeapMem_Handle heap, void * buf, size_t size);
391 
400 extern bool HeapMem_isBlocking(HeapMem_Handle heap);
401 
412 extern void HeapMem_getStats(HeapMem_Handle heap, Memory_Stats *statBuf);
413 
423 extern void HeapMem_getExtendedStats(HeapMem_Handle heap, HeapMem_ExtendedStats *statBuf);
424 
437 extern HeapMem_Handle HeapMem_create(const HeapMem_Params *params, Error_Block *eb);
438 
450 extern HeapMem_Handle HeapMem_construct(HeapMem_Struct *obj, const HeapMem_Params *params);
451 
460 extern void HeapMem_delete(HeapMem_Handle *heap);
461 
467 extern void HeapMem_destruct(HeapMem_Struct *obj);
468 
479 extern void HeapMem_restore(HeapMem_Handle heap);
480 
489 extern void HeapMem_init(void);
490 
502 extern void HeapMem_Params_init(HeapMem_Params *prms);
503 
512 extern HeapMem_Handle HeapMem_Object_first(void);
513 
524 extern HeapMem_Handle HeapMem_Object_next(HeapMem_Handle heap);
525 
527 static inline HeapMem_Handle HeapMem_handle(HeapMem_Struct *str)
528 {
529  return ((HeapMem_Handle)str);
530 }
531 
532 static inline HeapMem_Struct * HeapMem_struct(HeapMem_Handle h)
533 {
534  return ((HeapMem_Struct *)h);
535 }
536 
537 #define HeapMem_module ((HeapMem_Module_State *) &(HeapMem_Module_state))
538 
540 #ifdef __cplusplus
541 }
542 #endif
543 
544 #endif
545 
547 #undef ti_sysbios_heaps_HeapMem_long_names
548 #include "HeapMem_defs.h"
size_t size
Size of buffer being managed by this heap instance.
Definition: HeapMem.h:204
size_t minBlockAlign
Minimum alignment for each block allocated.
Definition: HeapMem.h:243
HeapMem_Handle HeapMem_construct(HeapMem_Struct *obj, const HeapMem_Params *params)
Construct a HeapMem heap.
void HeapMem_Params_init(HeapMem_Params *prms)
Initialize the HeapMem_Params structure with default values.
bool HeapMem_isBlocking(HeapMem_Handle heap)
This function queries the gate to determine if the alloc/free can be blocking.
size_t size
Size of buffer being managed by this heap instance.
Definition: HeapMem.h:260
Static and run-time memory manager.
void HeapMem_getExtendedStats(HeapMem_Handle heap, HeapMem_ExtendedStats *statBuf)
Retrieves the extended statistics for a HeapMem instance.
Opaque queue element.
Definition: Queue.h:204
void HeapMem_restore(HeapMem_Handle heap)
Restore heap to its original created state.
Runtime error manager.
Queue Manager.
void * buf
Buffer being managed by this heap instance.
Definition: HeapMem.h:198
Stat structure for the HeapMem_getExtendedStats function.
Definition: HeapMem.h:187
Error block.
Definition: Error.h:152
HeapMem_Handle HeapMem_Object_next(HeapMem_Handle heap)
return handle of the next HeapMem on HeapMem list
void HeapMem_delete(HeapMem_Handle *heap)
Delete a HeapMem heap.
void HeapMem_init(void)
Initialize instance at runtime.
Interface to heap functions.
void HeapMem_destruct(HeapMem_Struct *obj)
Destruct a HeapMem heap.
HeapMem_Handle HeapMem_create(const HeapMem_Params *params, Error_Block *eb)
Create a HeapMem heap.
HeapMem_Struct HeapMem_Object
Definition: HeapMem.h:325
Memory heap statistics.
Definition: Memory.h:94
HeapMem_Handle HeapMem_Object_first(void)
return handle of the first HeapMem on HeapMem list
Definition: HeapMem.h:219
void HeapMem_getStats(HeapMem_Handle heap, Memory_Stats *statBuf)
HeapMem_getStats will lock the heap using the HeapMem Gate while it retrieves the HeapMem&#39;s statistic...
void * buf
Buffer being managed by this heap instance.
Definition: HeapMem.h:254
void * HeapMem_alloc(HeapMem_Handle heap, size_t size, size_t align, Error_Block *eb)
The actual block returned may be larger than requested to satisfy alignment requirements, and its size will always be a multiple of the size of the HeapMem_Header data structure (usually 8 bytes)
void HeapMem_free(HeapMem_Handle heap, void *buf, size_t size)
HeapMem_free() places the memory block specified by addr and size back into the free pool of the heap...
© Copyright 1995-2022, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale