Embedded Wireless Framework
ewf_allocator_memory_pool.h
Go to the documentation of this file.
1 /************************************************************************/
10 #ifndef __ewf_allocator_memory_pool__h__included__
11 #define __ewf_allocator_memory_pool__h__included__
12 
13 #include "ewf_allocator.h"
14 #include "ewf_platform.h"
15 
19 {
20  union
21  {
22  ewf_allocator_memory_pool_block* next_free_ptr;
23  uint32_t data_ptr[1];
24  };
25 };
26 
30 {
31  uint8_t* pool_ptr;
32  ewf_allocator_memory_pool_block* next_free_ptr;
33  uint32_t pool_size;
34  uint32_t block_size;
35 #ifdef EWF_PLATFORM_HAS_THREADING
36  ewf_platform_mutex* mutex_ptr;
37 #endif
38 };
39 
40 ewf_result ewf_allocator_memory_pool_start(ewf_allocator* allocator_ptr);
41 
42 ewf_result ewf_allocator_memory_pool_stop(ewf_allocator* allocator_ptr);
43 
44 ewf_result ewf_allocator_memory_pool_allocate(ewf_allocator* allocator_ptr, void** p);
45 
46 ewf_result ewf_allocator_memory_pool_release(ewf_allocator* allocator_ptr, void* p);
47 
48 #ifdef EWF_PARAMETER_CHECKING
49 #define EWF_ALLOCATOR_MEMORY_POOL_INITIALIZE_HEADER(allocator_ptr) \
50 do { \
51 (allocator_ptr)->struct_magic = EWF_ALLOCATOR_STRUCT_MAGIC; \
52 (allocator_ptr)->struct_size = EWF_ALLOCATOR_STRUCT_SIZE; \
53 (allocator_ptr)->struct_version = EWF_ALLOCATOR_VERSION; \
54 (allocator_ptr)->struct_type = EWF_ALLOCATOR_TYPE_MEMORY_POOL; \
55 } while(0)
56 #else
57 #define EWF_ALLOCATOR_MEMORY_POOL_INITIALIZE_HEADER(allocator_ptr)
58 #endif /* EWF_PARAMETER_CHECKING */
59 
60 #ifdef EWF_PLATFORM_HAS_THREADING
61 #define EWF_ALLOCATOR_MEMORY_POOL_STATIC_DECLARE__MUTEX(mutex_ptr, name_symb) \
62 EWF_PLATFORM_MUTEX_STATIC_DECLARE(mutex_ptr, name_symb);
63 #else
64 #define EWF_ALLOCATOR_MEMORY_POOL_STATIC_DECLARE__MUTEX(mutex_ptr, name_symb)
65 #endif
66 
74 #define EWF_ALLOCATOR_MEMORY_POOL_STATIC_DECLARE(allocator_ptr, allocator_name_symb, block_count_param, block_size_param) \
75 do { \
76 static ewf_allocator_memory_pool_block ewf_allocator_memory_pool__buffer__##allocator_name_symb[ \
77  ((block_size_param > sizeof(ewf_allocator_memory_pool_block)) \
78  ? (block_size_param) : sizeof(ewf_allocator_memory_pool_block)) \
79  * (block_count_param + 1)]; \
80 static struct _ewf_allocator_memory_pool ewf_allocator_memory_pool__##allocator_name_symb = {0}; \
81 static ewf_allocator ewf_allocator__##allocator_name_symb = {0}; \
82 ewf_allocator_memory_pool__##allocator_name_symb.pool_ptr = (uint8_t*) ewf_allocator_memory_pool__buffer__##allocator_name_symb; \
83 ewf_allocator_memory_pool__##allocator_name_symb.pool_size = sizeof(ewf_allocator_memory_pool__buffer__##allocator_name_symb); \
84 ewf_allocator_memory_pool__##allocator_name_symb.block_size = (uint32_t) block_size_param; \
85 EWF_ALLOCATOR_MEMORY_POOL_STATIC_DECLARE__MUTEX(ewf_allocator_memory_pool__##allocator_name_symb.mutex_ptr, allocator_name_symb); \
86 ewf_allocator__##allocator_name_symb.block_size = block_size_param; \
87 ewf_allocator__##allocator_name_symb.block_count = block_count_param; \
88 ewf_allocator__##allocator_name_symb.start = ewf_allocator_memory_pool_start; \
89 ewf_allocator__##allocator_name_symb.stop = ewf_allocator_memory_pool_stop; \
90 ewf_allocator__##allocator_name_symb.allocate = ewf_allocator_memory_pool_allocate; \
91 ewf_allocator__##allocator_name_symb.release = ewf_allocator_memory_pool_release; \
92 ewf_allocator__##allocator_name_symb.implementation_ptr = &(ewf_allocator_memory_pool__##allocator_name_symb); \
93 allocator_ptr = &(ewf_allocator__##allocator_name_symb); \
94 EWF_ALLOCATOR_MEMORY_POOL_INITIALIZE_HEADER(allocator_ptr); \
95 } while(0)
96 
97 #endif /* __ewf_allocator_memory_pool__h__included__ */
The Embedded Wireless Framework Software Platform API.
enum _ewf_result ewf_result
Success and error result codes specific to the EWF API.
Definition: ewf_allocator_memory_pool.h:19
Definition: ewf_allocator_memory_pool.h:30
uint32_t block_size
Definition: ewf_allocator_memory_pool.h:34
uint32_t pool_size
Definition: ewf_allocator_memory_pool.h:33
The allocator structure definition.
Definition: ewf_allocator.h:27