µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
initialise-free-store.cpp File Reference

Go to the source code of this file.

Typedefs

using application_memory_resource = os::memory::first_fit_top
 
using rtos_memory_resource = os::memory::lifo
 

Functions

void os_rtos_application_out_of_memory_hook (void)
 Hook to handle out of memory in the application free store.
 
void os_rtos_system_out_of_memory_hook (void)
 Hook to handle out of memory in the RTOS dynamic memory.
 
void os_startup_initialize_free_store (void *heap_address, std::size_t heap_size_bytes)
 
void * sbrk (ptrdiff_t incr)
 

Variables

static std::aligned_storage< sizeof(application_memory_resource), alignof(application_memory_resource)>::type application_free_store
 

Typedef Documentation

◆ application_memory_resource

◆ rtos_memory_resource

Function Documentation

◆ os_startup_initialize_free_store()

void os_startup_initialize_free_store ( void *  heap_address,
std::size_t  heap_size_bytes 
)

This routine is called after the hardware is initialised, before the static constructors, to initialise the application free store and the RTOS dynamic memory (when OS_INTEGER_RTOS_DYNAMIC_MEMORY_SIZE_BYTES is defined).

If the RTOS is configured with its own memory, this area is dynamically allocated on the application free store. The RTOS memory resource (by default the one using LIFO) is also dynamically allocated on the application free store. (If it is free, why not use it; these areas are permanent anyway).

For special applications, it is possible to override this function entirely.

Definition at line 82 of file initialise-free-store.cpp.

84{
85 trace::printf ("%s(%p,%u)\n", __func__, heap_address, heap_size_bytes);
86
87#if !defined(OS_EXCLUDE_DYNAMIC_MEMORY_ALLOCATIONS)
88
89 // Construct the memory resource used for the application free store.
91 application_memory_resource{ "app", heap_address, heap_size_bytes };
92
93 // Configure the memory manager to throw an exception when out of memory.
95 ->out_of_memory_handler (os_rtos_application_out_of_memory_hook);
96
97 // Set the application free store memory manager.
100
101 // Adjust sbrk() to prevent it overlapping the free store.
102#pragma GCC diagnostic push
103#pragma GCC diagnostic ignored "-Wuseless-cast"
104 sbrk (
105 static_cast<char*> (static_cast<char*> (heap_address) + heap_size_bytes)
106 - static_cast<char*> (sbrk (0)));
107#pragma GCC diagnostic pop
108
109#if defined(OS_INTEGER_RTOS_DYNAMIC_MEMORY_SIZE_BYTES)
110
111 {
112 // Allocate the RTOS dynamic memory on the application free store.
113 void* rtos_arena
114 = reinterpret_cast<rtos::memory::memory_resource*> (
117
118 // Allocate & construct the memory resource used for the RTOS.
121 };
122
123 // Configure the memory manager to throw an exception when out of memory.
125
126 // Set RTOS system memory manager.
128 }
129
130#else
131
132 // The RTOS system memory manager is identical with the application one.
134 reinterpret_cast<rtos::memory::memory_resource*> (
136
137#endif /* defined(OS_INTEGER_RTOS_DYNAMIC_MEMORY_SIZE_BYTES) */
138
139#if defined(OS_INTEGER_RTOS_ALLOC_THREAD_POOL_SIZE)
140
141 {
143 "Mutex pool size must be >1.");
147
148 // Configure the memory manager to throw an exception when out of memory.
150
151 rtos::memory::set_resource_typed<rtos::thread> (mr);
152 }
153
154#endif /* defined(OS_INTEGER_RTOS_ALLOC_THREAD_POOL_SIZE) */
155
156#if defined(OS_INTEGER_RTOS_ALLOC_CONDITION_VARIABLE_POOL_SIZE)
157
158 {
160 "Mutex pool size must be >1.");
165
166 // Configure the memory manager to throw an exception when out of memory.
168
169 rtos::memory::set_resource_typed<rtos::condition_variable> (mr);
170 }
171
172#endif /* defined(OS_INTEGER_RTOS_ALLOC_CONDITION_VARIABLE_POOL_SIZE) */
173
174#if defined(OS_INTEGER_RTOS_ALLOC_EVENT_FLAGS_POOL_SIZE)
175
176 {
178 "Mutex pool size must be >1.");
182 "pool-ef");
183
184 // Configure the memory manager to throw an exception when out of memory.
186
187 rtos::memory::set_resource_typed<rtos::event_flags> (mr);
188 }
189
190#endif /* defined(OS_INTEGER_RTOS_ALLOC_EVENT_FLAGS_POOL_SIZE) */
191
192#if defined(OS_INTEGER_RTOS_ALLOC_MEMORY_POOL_POOL_SIZE)
193
194 {
196 "Mutex pool size must be >1.");
200 "pool-mp");
201
202 // Configure the memory manager to throw an exception when out of memory.
204
205 rtos::memory::set_resource_typed<rtos::memory_pool> (mr);
206 }
207
208#endif /* defined(OS_INTEGER_RTOS_ALLOC_MEMORY_POOL_POOL_SIZE) */
209
210#if defined(OS_INTEGER_RTOS_ALLOC_MESSAGE_QUEUE_POOL_SIZE)
211
212 {
214 "Mutex pool size must be >1.");
219
220 // Configure the memory manager to throw an exception when out of memory.
222
223 rtos::memory::set_resource_typed<rtos::message_queue> (mr);
224 }
225
226#endif /* defined(OS_INTEGER_RTOS_ALLOC_MESSAGE_QUEUE_POOL_SIZE) */
227
228#if defined(OS_INTEGER_RTOS_ALLOC_MUTEX_POOL_SIZE)
229
230 {
231 static_assert (OS_INTEGER_RTOS_ALLOC_MUTEX_POOL_SIZE > 1,
232 "Mutex pool size must be >1.");
236
237 // Configure the memory manager to throw an exception when out of memory.
239
240 rtos::memory::set_resource_typed<rtos::mutex> (mr);
241 }
242
243#endif /* defined(OS_INTEGER_RTOS_ALLOC_MUTEX_POOL_SIZE) */
244
245#if defined(OS_INTEGER_RTOS_ALLOC_SEMAPHORE_POOL_SIZE)
246
247 {
249 "Semaphore pool size must be >1.");
253 "pool-sp");
254
255 // Configure the memory manager to throw an exception when out of memory.
257
258 rtos::memory::set_resource_typed<rtos::semaphore> (mr);
259 }
260
261#endif /* defined(OS_INTEGER_RTOS_ALLOC_SEMAPHORE_POOL_SIZE) */
262
263#if defined(OS_INTEGER_RTOS_ALLOC_TIMER_POOL_SIZE)
264
265 {
266 static_assert (OS_INTEGER_RTOS_ALLOC_TIMER_POOL_SIZE > 1,
267 "Mutex pool size must be >1.");
271
272 // Configure the memory manager to throw an exception when out of memory.
274
275 rtos::memory::set_resource_typed<rtos::timer> (mr);
276 }
277
278#endif /* defined(OS_INTEGER_RTOS_ALLOC_TIMER_POOL_SIZE) */
279
280#endif /* !defined(OS_EXCLUDE_DYNAMIC_MEMORY_ALLOCATIONS) */
281}
Memory resource managing an internal pool. of same size blocks of type T.
Definition block-pool.h:245
Memory resource implementing the first fit, top-down allocation policies, using an existing arena.
Memory resource implementing the LIFO allocation/deallocation policies, using an existing arena.
Definition lifo.h:72
POSIX compliant condition variable.
Definition os-condvar.h:45
Synchronised event flags.
Definition os-evflags.h:57
Memory resource manager (abstract class).
Definition os-memory.h:159
out_of_memory_handler_t out_of_memory_handler(out_of_memory_handler_t handler)
Set the out of memory handler.
Definition os-memory.h:1375
Synchronised memory pool, using the default RTOS allocator.
Definition os-mempool.h:67
POSIX compliant message queue, using the default RTOS allocator.
Definition os-mqueue.h:67
POSIX compliant mutex.
Definition os-mutex.h:52
POSIX compliant semaphore.
POSIX compliant thread, using the default RTOS allocator.
Definition os-thread.h:251
User single-shot or periodic timer.
Definition os-timer.h:56
#define OS_INTEGER_RTOS_ALLOC_THREAD_POOL_SIZE
Define a pool of thread objects.
#define OS_INTEGER_RTOS_ALLOC_EVENT_FLAGS_POOL_SIZE
Define a pool of event flags objects.
#define OS_INTEGER_RTOS_ALLOC_SEMAPHORE_POOL_SIZE
Define a pool of semaphore objects.
#define OS_INTEGER_RTOS_ALLOC_CONDITION_VARIABLE_POOL_SIZE
Define a pool of condition variable objects.
#define OS_INTEGER_RTOS_ALLOC_MUTEX_POOL_SIZE
Define a pool of mutex objects.
#define OS_INTEGER_RTOS_ALLOC_MEMORY_POOL_POOL_SIZE
Define a pool of memory pool objects.
#define OS_INTEGER_RTOS_ALLOC_TIMER_POOL_SIZE
Define a pool of timer objects.
#define OS_INTEGER_RTOS_ALLOC_MESSAGE_QUEUE_POOL_SIZE
Define a pool of message queue objects.
#define OS_INTEGER_RTOS_DYNAMIC_MEMORY_SIZE_BYTES
Ask for separate RTOS dynamic memory and define its size.
void os_rtos_application_out_of_memory_hook(void)
Hook to handle out of memory in the application free store.
void os_rtos_system_out_of_memory_hook(void)
Hook to handle out of memory in the RTOS dynamic memory.
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59
memory_resource * set_default_resource(memory_resource *res) noexcept
Set the default RTOS system memory manager.
memory_resource * set_default_resource(memory_resource *res) noexcept
Set the default application memory manager.
static std::aligned_storage< sizeof(application_memory_resource), alignof(application_memory_resource)>::type application_free_store
void * sbrk(ptrdiff_t incr)

References application_free_store, OS_INTEGER_RTOS_ALLOC_CONDITION_VARIABLE_POOL_SIZE, OS_INTEGER_RTOS_ALLOC_EVENT_FLAGS_POOL_SIZE, OS_INTEGER_RTOS_ALLOC_MEMORY_POOL_POOL_SIZE, OS_INTEGER_RTOS_ALLOC_MESSAGE_QUEUE_POOL_SIZE, OS_INTEGER_RTOS_ALLOC_MUTEX_POOL_SIZE, OS_INTEGER_RTOS_ALLOC_SEMAPHORE_POOL_SIZE, OS_INTEGER_RTOS_ALLOC_THREAD_POOL_SIZE, OS_INTEGER_RTOS_ALLOC_TIMER_POOL_SIZE, OS_INTEGER_RTOS_DYNAMIC_MEMORY_SIZE_BYTES, os_rtos_application_out_of_memory_hook(), os_rtos_system_out_of_memory_hook(), os::rtos::memory::memory_resource::out_of_memory_handler(), os::trace::printf(), sbrk(), os::estd::pmr::set_default_resource(), and os::rtos::memory::set_default_resource().

◆ sbrk()

void * sbrk ( ptrdiff_t  incr)

Variable Documentation

◆ application_free_store

std::aligned_storage<sizeof(application_memory_resource),alignof(application_memory_resource)>::type application_free_store
static

Definition at line 61 of file initialise-free-store.cpp.

Referenced by os_startup_initialize_free_store().