µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
os::memory::block_pool Class Reference

Memory resource managing a pool of same size blocks, using an existing arena. More...

#include <cmsis-plus/memory/block-pool.h>

+ Inheritance diagram for os::memory::block_pool:

Public Member Functions

Public Member Functions
void * allocate (std::size_t bytes, std::size_t alignment=max_align)
 Allocate a memory block.
 
void deallocate (void *addr, std::size_t bytes, std::size_t alignment=max_align) noexcept
 Deallocate the previously allocated memory block.
 
bool is_equal (memory_resource const &other) const noexcept
 Compare for equality with another memory_resource.
 
void reset (void) noexcept
 Reset the memory manager to the initial state.
 
bool coalesce (void) noexcept
 Coalesce free blocks.
 
std::size_t max_size (void) const noexcept
 Get the largest value that can be passed to allocate().
 
out_of_memory_handler_t out_of_memory_handler (out_of_memory_handler_t handler)
 Set the out of memory handler.
 
out_of_memory_handler_t out_of_memory_handler (void)
 Get the out of memory handler.
 
std::size_t total_bytes (void)
 Get the total size of managed memory.
 
std::size_t allocated_bytes (void)
 Get the current size of all allocated chunks.
 
std::size_t max_allocated_bytes (void)
 Get the maximum allocated size.
 
std::size_t free_bytes (void)
 Get the current size of all free chunks.
 
std::size_t allocated_chunks (void)
 Get the current number of allocated chunks.
 
std::size_t free_chunks (void)
 Get the current number of free chunks.
 
std::size_t allocations (void)
 Get the number of allocations.
 
std::size_t deallocations (void)
 Get the number of deallocations.
 
void trace_print_statistics (void)
 Print a long message with usage statistics.
 
Public Member Functions
const char * name (void) const
 Get object name.
 

Static Public Attributes

static constexpr std::size_t max_align = alignof (std::max_align_t)
 The largest alignment for the platform. Also default when supplied alignment is not supported.
 

Protected Member Functions

Private Member Functions
void internal_construct_ (std::size_t blocks, std::size_t block_size_bytes, void *addr, std::size_t bytes) noexcept
 Internal function to construct the memory resource object instance.
 
void internal_reset_ (void) noexcept
 Internal function to reset the memory resource object.
 
virtual void * do_allocate (std::size_t bytes, std::size_t alignment) override
 Implementation of the memory allocator.
 
virtual void do_deallocate (void *addr, std::size_t bytes, std::size_t alignment) noexcept override
 Implementation of the memory deallocator.
 
virtual std::size_t do_max_size (void) const noexcept override
 Implementation of the function to get max size.
 
virtual void do_reset (void) noexcept override
 Implementation of the function to reset the memory manager.
 
Private Member Functions
virtual bool do_is_equal (memory_resource const &other) const noexcept
 Implementation of the equality comparator.
 
virtual bool do_coalesce (void) noexcept
 Implementation of the function to coalesce free blocks.
 
void internal_increase_allocated_statistics (std::size_t bytes) noexcept
 Update statistics after allocation.
 
void internal_decrease_allocated_statistics (std::size_t bytes) noexcept
 Update statistics after deallocation.
 

Constructors & Destructor

 block_pool (std::size_t blocks, std::size_t block_size_bytes, void *addr, std::size_t bytes)
 Construct a memory resource object instance.
 
 block_pool (const char *name, std::size_t blocks, std::size_t block_size_bytes, void *addr, std::size_t bytes)
 Construct a named memory resource object instance.
 
virtual ~block_pool () override
 Destruct the memory resource object instance.
 
 block_pool (const char *name)
 Default constructor. Construct a memory resource object instance.
 

Detailed Description

This class is a deterministic, non-fragmenting memory manager, that allocates identical size blocks from a pool.

This memory manager is ideal for allocation of system objects.

The only drawback is that the maximum number of objects must be known before the first allocations, but usually this is not a problem.

Definition at line 55 of file block-pool.h.

Constructor & Destructor Documentation

◆ block_pool() [1/3]

os::memory::block_pool::block_pool ( std::size_t  blocks,
std::size_t  block_size_bytes,
void *  addr,
std::size_t  bytes 
)
inline
Parameters
[in]blocksThe maximum number of items in the pool.
[in]block_size_bytesThe size of an item, in bytes.
[in]addrBegin of allocator arena.
[in]bytesSize of allocator arena, in bytes.

Definition at line 462 of file block-pool.h.

465 : block_pool{ nullptr, blocks, block_size_bytes, addr, bytes }
466 {
467 }
block_pool(std::size_t blocks, std::size_t block_size_bytes, void *addr, std::size_t bytes)
Construct a memory resource object instance.
Definition block-pool.h:462

◆ block_pool() [2/3]

os::memory::block_pool::block_pool ( const char *  name,
std::size_t  blocks,
std::size_t  block_size_bytes,
void *  addr,
std::size_t  bytes 
)
inline
Parameters
namePointer to name.
[in]blocksThe maximum number of items in the pool.
[in]block_size_bytesThe size of an item, in bytes.
[in]addrBegin of allocator arena.
[in]bytesSize of allocator arena, in bytes.

Definition at line 469 of file block-pool.h.

472 : rtos::memory::memory_resource{ name }
473 {
474 trace::printf ("%s(%u,%u,%p,%u) @%p %s\n", __func__, blocks,
475 block_size_bytes, addr, bytes, this, this->name ());
476
477 internal_construct_ (blocks, block_size_bytes, addr, bytes);
478 }
void internal_construct_(std::size_t blocks, std::size_t block_size_bytes, void *addr, std::size_t bytes) noexcept
Internal function to construct the memory resource object instance.
const char * name(void) const
Get object name.
Definition os-decls.h:753
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59

References internal_construct_(), and os::trace::printf().

◆ block_pool() [3/3]

os::memory::block_pool::block_pool ( const char *  name)
inlineprotected

Definition at line 457 of file block-pool.h.

458 : rtos::memory::memory_resource{ name }
459 {
460 }

◆ ~block_pool()

os::memory::block_pool::~block_pool ( )
overridevirtual

Definition at line 34 of file block-pool.cpp.

35 {
36 trace::printf ("%s() @%p %s\n", __func__, this, this->name ());
37 }

References os::rtos::internal::object_named::name(), and os::trace::printf().

Member Function Documentation

◆ allocate()

void * os::rtos::memory::memory_resource::allocate ( std::size_t  bytes,
std::size_t  alignment = max_align 
)
inlineinherited
Parameters
bytesNumber of bytes to allocate.
alignmentAlignment constraint (power of 2).
Returns
Pointer to newly allocated block, or nullptr.

Allocate storage with a size of at least bytes bytes. The returned storage is aligned to the specified alignment if such alignment is supported, and to alignof(std::max_align_t) otherwise.

If the storage of the requested size and alignment cannot be obtained:

  • if the out of memory handler is not set, return nullptr;
  • if the out of memory handler is set, call it and retry.

Equivalent to return do_allocate(bytes, alignment);.

Exceptions
The code itself throws nothing, but if the out of memory handler is set, it may throw a bad_alloc() exception.
See also
do_allocate();

Definition at line 1290 of file os-memory.h.

1291 {
1292 ++allocations_;
1293 return do_allocate (bytes, alignment);
1294 }
virtual void * do_allocate(std::size_t bytes, std::size_t alignment)=0
Implementation of the memory allocator.

References os::rtos::memory::memory_resource::do_allocate().

Referenced by os::estd::pmr::polymorphic_allocator< T >::allocate(), calloc(), malloc(), operator new(), and realloc().

◆ allocated_bytes()

std::size_t os::rtos::memory::memory_resource::allocated_bytes ( void  )
inlineinherited
Parameters
None.
Returns
Number of bytes.

Definition at line 1402 of file os-memory.h.

1403 {
1404 return allocated_bytes_;
1405 }

Referenced by os::rtos::memory::memory_resource::trace_print_statistics().

◆ allocated_chunks()

std::size_t os::rtos::memory::memory_resource::allocated_chunks ( void  )
inlineinherited
Parameters
None.
Returns
Number of chunks.

Definition at line 1420 of file os-memory.h.

1421 {
1422 return allocated_chunks_;
1423 }

Referenced by os::rtos::memory::memory_resource::trace_print_statistics().

◆ allocations()

std::size_t os::rtos::memory::memory_resource::allocations ( void  )
inlineinherited
Parameters
None.
Returns
Number of allocations.

Definition at line 1432 of file os-memory.h.

1433 {
1434 return allocations_;
1435 }

Referenced by os::rtos::memory::memory_resource::trace_print_statistics().

◆ coalesce()

bool os::rtos::memory::memory_resource::coalesce ( void  )
inlinenoexceptinherited
Parameters
None.
Return values
trueif the operation freed more memory.
falseif the operation was ineffective.

In case the memory manager does not coalesce during deallocation, traverse the list of free blocks and coalesce.

Return true if the operation was successful and at least one larger block resulted.

See also
do_coalesce();

Definition at line 1365 of file os-memory.h.

1366 {
1367 return do_coalesce ();
1368 }
virtual bool do_coalesce(void) noexcept
Implementation of the function to coalesce free blocks.

◆ deallocate()

void os::rtos::memory::memory_resource::deallocate ( void *  addr,
std::size_t  bytes,
std::size_t  alignment = max_align 
)
inlinenoexceptinherited
Parameters
addrAddress of the block to free.
bytesNumber of bytes to deallocate (may be 0 if unknown).
alignmentAlignment constraint (power of 2).
Returns
Nothing.

Deallocate the storage pointed to by addr. The address shall have been returned by a prior call to allocate() on a memory_resource that compares equal to *this, and the storage it points to shall not yet have been deallocated.

Equivalent to return do_deallocate(p, bytes, alignment);.

Exceptions
Throws nothing.
See also
do_deallocate();

Definition at line 1312 of file os-memory.h.

1314 {
1315 ++deallocations_;
1316 do_deallocate (addr, bytes, alignment);
1317 }
virtual void do_deallocate(void *addr, std::size_t bytes, std::size_t alignment) noexcept=0
Implementation of the memory deallocator.

Referenced by os::estd::pmr::polymorphic_allocator< T >::deallocate(), free(), and realloc().

◆ deallocations()

std::size_t os::rtos::memory::memory_resource::deallocations ( void  )
inlineinherited
Parameters
None.
Returns
Number of deallocations

Definition at line 1438 of file os-memory.h.

1439 {
1440 return deallocations_;
1441 }

Referenced by os::rtos::memory::memory_resource::trace_print_statistics().

◆ do_allocate()

void * os::memory::block_pool::do_allocate ( std::size_t  bytes,
std::size_t  alignment 
)
overrideprotectedvirtual
Parameters
[in]bytesNumber of bytes to allocate.
[in]alignmentAlignment constraint (power of 2).
Returns
Pointer to newly allocated block, or nullptr.

Implements os::rtos::memory::memory_resource.

Definition at line 47 of file block-pool.cpp.

48 {
49 assert (bytes <= block_size_bytes_);
50
51 if (first_ == nullptr)
52 {
53 return nullptr;
54 }
55
56 void* p = static_cast<void*> (first_);
57 first_ = *(static_cast<void**> (first_));
58
59#pragma GCC diagnostic push
60#if defined(__clang__)
61#pragma clang diagnostic ignored "-Wdeprecated-volatile"
62#elif defined(__GNUC__)
63#pragma GCC diagnostic ignored "-Wvolatile"
64#endif
65 ++count_;
66#pragma GCC diagnostic pop
67
68 // Update statistics.
69 // What is subtracted from free is added to allocated.
71
72#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
73 trace::printf ("%s(%u,%u)=%p,%u @%p %s\n", __func__, bytes, alignment, p,
74 block_size_bytes_, this, name ());
75#endif
76
77 return p;
78 }
void internal_increase_allocated_statistics(std::size_t bytes) noexcept
Update statistics after allocation.

References os::rtos::memory::memory_resource::internal_increase_allocated_statistics(), os::rtos::internal::object_named::name(), and os::trace::printf().

◆ do_coalesce()

bool os::rtos::memory::memory_resource::do_coalesce ( void  )
protectedvirtualnoexceptinherited
Parameters
None.
Return values
trueif the operation resulted in larger blocks.
falseif the operation was ineffective.

The default implementation of this virtual function returns false, meaning the operation was ineffective.

Override this function to perform the action.

Standard compliance
Extension to standard.

Definition at line 468 of file os-memory.cpp.

469 {
470 return false;
471 }

◆ do_deallocate()

void os::memory::block_pool::do_deallocate ( void *  addr,
std::size_t  bytes,
std::size_t  alignment 
)
overrideprotectedvirtualnoexcept
Parameters
[in]addrAddress of a previously allocated block to free.
[in]bytesNumber of bytes to deallocate (may be 0 if unknown).
[in]alignmentAlignment constraint (power of 2).
Returns
Nothing.

Implements os::rtos::memory::memory_resource.

Definition at line 81 of file block-pool.cpp.

83 {
84#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
85 trace::printf ("%s(%p,%u,%u) @%p %s\n", __func__, addr, bytes, alignment,
86 this, name ());
87#endif
88
89#pragma GCC diagnostic push
90#if defined(__clang__)
91#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
92#endif
93 if ((addr < pool_addr_)
94 || (addr >= (static_cast<char*> (pool_addr_)
95 + blocks_ * block_size_bytes_)))
96 {
97 assert (false);
98 return;
99 }
100#pragma GCC diagnostic pop
101
102 // Perform a push_front() on the single linked LIFO list,
103 // i.e. add the block to the beginning of the list.
104
105 // Link previous list to this block; may be null, but it does
106 // not matter.
107 *(static_cast<void**> (addr)) = first_;
108
109 // Now this block is the first in the free list..
110 first_ = addr;
111
112#pragma GCC diagnostic push
113#if defined(__clang__)
114#pragma clang diagnostic ignored "-Wdeprecated-volatile"
115#elif defined(__GNUC__)
116#pragma GCC diagnostic ignored "-Wvolatile"
117#endif
118 --count_;
119#pragma GCC diagnostic pop
120
121 // Update statistics.
122 // What is subtracted from allocated is added to free.
123 internal_decrease_allocated_statistics (block_size_bytes_);
124 }
void internal_decrease_allocated_statistics(std::size_t bytes) noexcept
Update statistics after deallocation.

References os::trace::printf().

◆ do_is_equal()

bool os::rtos::memory::memory_resource::do_is_equal ( memory_resource const &  other) const
protectedvirtualnoexceptinherited
Parameters
otherReference to another memory_resource.
Return values
trueThe memory_resource objects are equal.
falseThe memory_resource objects are not equal.

Compares *this for equality with other. Two memory_resources compare equal if and only if memory allocated from one memory_resource can be deallocated from the other and vice versa.

The most-derived type of other may not match the most derived type of *this. A derived class implementation therefore must typically check whether the most derived types of *this and other match using dynamic_cast, and immediately return false if the cast fails.

Exceptions
Throws nothing.

Definition at line 419 of file os-memory.cpp.

421 {
422 return &other == this;
423 }

◆ do_max_size()

std::size_t os::memory::block_pool::do_max_size ( void  ) const
overrideprotectedvirtualnoexcept
Parameters
None.
Returns
Integer with size in bytes, or 0 if unknown.

Reimplemented from os::rtos::memory::memory_resource.

Definition at line 129 of file block-pool.cpp.

130 {
131 return block_size_bytes_ * blocks_;
132 }

◆ do_reset()

void os::memory::block_pool::do_reset ( void  )
overrideprotectedvirtualnoexcept
Parameters
None.
Returns
Nothing.

Reimplemented from os::rtos::memory::memory_resource.

Definition at line 135 of file block-pool.cpp.

136 {
137#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
138 trace::printf ("%s() @%p %s\n", __func__, this, name ());
139#endif
141 }
void internal_reset_(void) noexcept
Internal function to reset the memory resource object.

References os::trace::printf().

◆ free_bytes()

std::size_t os::rtos::memory::memory_resource::free_bytes ( void  )
inlineinherited
Parameters
None.
Returns
Number of bytes.

Definition at line 1414 of file os-memory.h.

1415 {
1416 return free_bytes_;
1417 }

Referenced by os::rtos::memory::memory_resource::trace_print_statistics().

◆ free_chunks()

std::size_t os::rtos::memory::memory_resource::free_chunks ( void  )
inlineinherited
Parameters
None.
Returns
Number of chunks.

Definition at line 1426 of file os-memory.h.

1427 {
1428 return free_chunks_;
1429 }

Referenced by os::rtos::memory::memory_resource::trace_print_statistics().

◆ internal_construct_()

void os::memory::block_pool::internal_construct_ ( std::size_t  blocks,
std::size_t  block_size_bytes,
void *  addr,
std::size_t  bytes 
)
protectednoexcept
Parameters
[in]blocksThe maximum number of items in the pool.
[in]block_size_bytesThe size of an item, in bytes.
[in]addrBegin of allocator arena.
[in]bytesSize of allocator arena, in bytes.
Returns
Nothing.

Definition at line 144 of file block-pool.cpp.

147 {
148 blocks_ = blocks;
149
150 block_size_bytes_
151 = rtos::memory::align_size (block_size_bytes, alignof (void*));
152 assert (block_size_bytes_ >= sizeof (void*));
153
154 assert (addr != nullptr);
155 pool_addr_ = addr;
156
157 std::size_t align_sz = bytes;
158
159 void* res;
160 // Possibly adjust the last two parameters.
161 res = std::align (alignof (void*), blocks * block_size_bytes_,
162 pool_addr_, align_sz);
163
164 // std::align() will fail if it cannot fit the adjusted block size.
165 if (res != nullptr)
166 {
167 assert (res != nullptr);
168 }
169
170 // The extra assert is made redundant by std::align().
171 // assert(blocks * block_size_bytes_ <= align_sz);
172
173 total_bytes_ = blocks_ * block_size_bytes_;
174
176 }
constexpr std::size_t align_size(std::size_t size, std::size_t align) noexcept
Helper function to align size values.
Definition os-memory.h:85

References os::rtos::memory::align_size().

Referenced by block_pool(), os::memory::block_pool_typed_allocated< T, A >::block_pool_typed_allocated(), and os::memory::block_pool_typed_inclusive< T, N >::block_pool_typed_inclusive().

◆ internal_decrease_allocated_statistics()

void os::rtos::memory::memory_resource::internal_decrease_allocated_statistics ( std::size_t  bytes)
protectednoexceptinherited
Parameters
[in]bytesNumber of deallocated bytes.
Returns
Nothing.

Definition at line 490 of file os-memory.cpp.

492 {
493 // Update statistics.
494 // What is subtracted from allocated is added to free.
495 allocated_bytes_ -= bytes;
496 free_bytes_ += bytes;
497 --allocated_chunks_;
498 ++free_chunks_;
499 }

◆ internal_increase_allocated_statistics()

void os::rtos::memory::memory_resource::internal_increase_allocated_statistics ( std::size_t  bytes)
protectednoexceptinherited
Parameters
[in]bytesNumber of allocated bytes.
Returns
Nothing.

Definition at line 474 of file os-memory.cpp.

476 {
477 // Update statistics.
478 // What is subtracted from free is added to allocated.
479 allocated_bytes_ += bytes;
480 if (allocated_bytes_ > max_allocated_bytes_)
481 {
482 max_allocated_bytes_ = allocated_bytes_;
483 }
484 free_bytes_ -= bytes;
485 ++allocated_chunks_;
486 --free_chunks_;
487 }

Referenced by do_allocate(), and os::memory::first_fit_top::internal_align_().

◆ internal_reset_()

void os::memory::block_pool::internal_reset_ ( void  )
protectednoexcept
Parameters
None.
Returns
Nothing.

Definition at line 179 of file block-pool.cpp.

180 {
181 // Construct a linked list of blocks. Store the pointer at
182 // the beginning of each block. Each block
183 // will hold the address of the next free block, or nullptr at the end.
184#pragma GCC diagnostic push
185#if defined(__clang__)
186#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
187#endif
188 char* p = static_cast<char*> (pool_addr_);
189 for (std::size_t i = 1; i < blocks_; ++i)
190 {
191 // Compute the address of the next block;
192 char* pn = p + block_size_bytes_;
193
194 // Make this block point to the next one.
195 *(static_cast<void**> (static_cast<void*> (p))) = pn;
196 // Advance pointer
197 p = pn;
198 }
199#pragma GCC diagnostic pop
200
201 // Mark end of list.
202 *(static_cast<void**> (static_cast<void*> (p))) = nullptr;
203
204 first_ = pool_addr_; // Pointer to first block.
205
206 count_ = 0; // No allocated blocks.
207
208 allocated_bytes_ = 0;
209 max_allocated_bytes_ = 0;
210 free_bytes_ = total_bytes_;
211 allocated_chunks_ = 0;
212 free_chunks_ = blocks_;
213 }

◆ is_equal()

bool os::rtos::memory::memory_resource::is_equal ( memory_resource const &  other) const
inlinenoexceptinherited
Parameters
otherReference to another memory_resource.
Return values
trueThe memory_resource objects are equal.
falseThe memory_resource objects are not equal.

Compare *this for equality with other. Two memory_resources compare equal if and only if memory allocated from one memory_resource can be deallocated from the other and vice versa.

Exceptions
Throws nothing.
See also
do_is_equal();

Definition at line 1331 of file os-memory.h.

1332 {
1333 return do_is_equal (other);
1334 }
virtual bool do_is_equal(memory_resource const &other) const noexcept
Implementation of the equality comparator.

◆ max_allocated_bytes()

std::size_t os::rtos::memory::memory_resource::max_allocated_bytes ( void  )
inlineinherited
Parameters
None.
Returns
Number of bytes.

Definition at line 1408 of file os-memory.h.

1409 {
1410 return max_allocated_bytes_;
1411 }

Referenced by os::rtos::memory::memory_resource::trace_print_statistics().

◆ max_size()

std::size_t os::rtos::memory::memory_resource::max_size ( void  ) const
inlinenoexceptinherited
Parameters
None.
Returns
Number of bytes or 0 if unknown.
See also
do_max_size();

Definition at line 1340 of file os-memory.h.

1341 {
1342 return do_max_size ();
1343 }
virtual std::size_t do_max_size(void) const noexcept
Implementation of the function to get max size.

◆ name()

const char * os::rtos::internal::object_named::name ( void  ) const
inlineinherited
Parameters
None.
Returns
A null terminated string.

All objects return a non-null string; anonymous objects return "-".

Note
Can be invoked from Interrupt Service Routines.

Definition at line 753 of file os-decls.h.

754 {
755 return name_;
756 }

Referenced by os::memory::lifo::lifo(), os::memory::malloc_memory_resource::malloc_memory_resource(), os::rtos::message_queue_typed< T, Allocator >::message_queue_typed(), ~block_pool(), os::rtos::event_flags::~event_flags(), os::memory::first_fit_top::~first_fit_top(), os::memory::lifo::~lifo(), os::memory::malloc_memory_resource::~malloc_memory_resource(), os::rtos::memory_pool::~memory_pool(), os::rtos::message_queue::~message_queue(), os::rtos::mutex::~mutex(), os::rtos::semaphore::~semaphore(), os::rtos::thread::~thread(), os::rtos::timer::~timer(), os::rtos::memory_pool::alloc(), os::rtos::thread::cancel(), os::rtos::event_flags::clear(), os::rtos::mutex::consistent(), os::rtos::thread::detach(), os::memory::new_delete_memory_resource::do_allocate(), do_allocate(), os::memory::first_fit_top::do_allocate(), os::memory::lifo::do_allocate(), os::memory::malloc_memory_resource::do_allocate(), os::rtos::thread::flags_raise(), os::rtos::memory_pool::free(), os::rtos::event_flags::get(), os::rtos::thread::interrupt(), os::rtos::thread::join(), os::rtos::thread::kill(), os::rtos::internal::terminated_threads_list::link(), os::rtos::mutex::lock(), os::rtos::memory::memory_resource::out_of_memory_handler(), os::rtos::semaphore::post(), os::rtos::mutex::prio_ceiling(), os::rtos::mutex::prio_ceiling(), os::rtos::thread::priority(), os::rtos::thread::priority_inherited(), os::rtos::event_flags::raise(), os::rtos::message_queue::receive(), os::rtos::memory_pool::reset(), os::rtos::message_queue::reset(), os::rtos::mutex::reset(), os::rtos::semaphore::reset(), os::rtos::thread::resume(), os::rtos::message_queue::send(), os::rtos::clock::sleep_for(), os::rtos::timer::start(), os::rtos::timer::stop(), os::rtos::memory_pool::timed_alloc(), os::rtos::mutex::timed_lock(), os::rtos::message_queue::timed_receive(), os::rtos::message_queue::timed_send(), os::rtos::semaphore::timed_wait(), os::rtos::event_flags::timed_wait(), os::rtos::memory::memory_resource::trace_print_statistics(), os::rtos::memory_pool::try_alloc(), os::rtos::mutex::try_lock(), os::rtos::message_queue::try_receive(), os::rtos::message_queue::try_send(), os::rtos::event_flags::try_wait(), os::rtos::semaphore::try_wait(), os::rtos::internal::ready_threads_list::unlink_head(), os::rtos::mutex::unlock(), os::rtos::event_flags::wait(), os::rtos::semaphore::wait(), and os::rtos::event_flags::waiting().

◆ out_of_memory_handler() [1/2]

out_of_memory_handler_t os::rtos::memory::memory_resource::out_of_memory_handler ( out_of_memory_handler_t  handler)
inlineinherited
Parameters
handlerPointer to new handler.
Returns
Pointer to old handler.
Standard compliance
Extension to standard.

Definition at line 1375 of file os-memory.h.

1376 {
1377 trace::printf ("%s(%p) @%p %s\n", __func__, handler, this, name ());
1378
1379 out_of_memory_handler_t tmp = out_of_memory_handler_;
1380 out_of_memory_handler_ = handler;
1381
1382 return tmp;
1383 }
void(*)(void) out_of_memory_handler_t
Type of out of memory handler.
Definition os-memory.h:141

References os::rtos::internal::object_named::name(), and os::trace::printf().

Referenced by os_startup_initialize_free_store().

◆ out_of_memory_handler() [2/2]

out_of_memory_handler_t os::rtos::memory::memory_resource::out_of_memory_handler ( void  )
inlineinherited
Parameters
None.
Returns
Pointer to existing handler.
Standard compliance
Extension to standard.

Definition at line 1390 of file os-memory.h.

1391 {
1392 return out_of_memory_handler_;
1393 }

◆ reset()

void os::rtos::memory::memory_resource::reset ( void  )
inlinenoexceptinherited
Parameters
None.
Returns
Nothing.
See also
do_reset();

Definition at line 1349 of file os-memory.h.

1350 {
1351 do_reset ();
1352 }
virtual void do_reset(void) noexcept
Implementation of the function to reset the memory manager.

◆ total_bytes()

std::size_t os::rtos::memory::memory_resource::total_bytes ( void  )
inlineinherited
Returns
Number of bytes.

Definition at line 1396 of file os-memory.h.

1397 {
1398 return total_bytes_;
1399 }

Referenced by os::rtos::memory::memory_resource::trace_print_statistics().

◆ trace_print_statistics()

void os::rtos::memory::memory_resource::trace_print_statistics ( void  )
inlineinherited
Parameters
None.
Returns
Nothing.

Definition at line 1444 of file os-memory.h.

1445 {
1446#if defined(TRACE)
1447 trace::printf ("Memory '%s' @%p: \n"
1448 "\ttotal: %u bytes, \n"
1449 "\tallocated: %u bytes in %u chunk(s), \n"
1450 "\tfree: %u bytes in %u chunk(s), \n"
1451 "\tmax: %u bytes, \n"
1452 "\tcalls: %u allocs, %u deallocs\n",
1453 name (), this, total_bytes (), allocated_bytes (),
1456 deallocations ());
1457#endif /* defined(TRACE) */
1458 }
std::size_t allocated_chunks(void)
Get the current number of allocated chunks.
Definition os-memory.h:1420
std::size_t allocated_bytes(void)
Get the current size of all allocated chunks.
Definition os-memory.h:1402
std::size_t max_allocated_bytes(void)
Get the maximum allocated size.
Definition os-memory.h:1408
std::size_t allocations(void)
Get the number of allocations.
Definition os-memory.h:1432
std::size_t total_bytes(void)
Get the total size of managed memory.
Definition os-memory.h:1396
std::size_t deallocations(void)
Get the number of deallocations.
Definition os-memory.h:1438
std::size_t free_chunks(void)
Get the current number of free chunks.
Definition os-memory.h:1426
std::size_t free_bytes(void)
Get the current size of all free chunks.
Definition os-memory.h:1414

References os::rtos::memory::memory_resource::allocated_bytes(), os::rtos::memory::memory_resource::allocated_chunks(), os::rtos::memory::memory_resource::allocations(), os::rtos::memory::memory_resource::deallocations(), os::rtos::memory::memory_resource::free_bytes(), os::rtos::memory::memory_resource::free_chunks(), os::rtos::memory::memory_resource::max_allocated_bytes(), os::rtos::internal::object_named::name(), os::trace::printf(), and os::rtos::memory::memory_resource::total_bytes().

Referenced by os_terminate_goodbye().

Member Data Documentation

◆ max_align

constexpr std::size_t os::rtos::memory::memory_resource::max_align = alignof (std::max_align_t)
staticconstexprinherited

Definition at line 166 of file os-memory.h.


The documentation for this class was generated from the following files: