12#ifndef CMSIS_PLUS_MEMORY_BLOCK_POOL_H_
13#define CMSIS_PLUS_MEMORY_BLOCK_POOL_H_
17#if defined(__cplusplus)
25#pragma GCC diagnostic push
27#pragma clang diagnostic ignored "-Wc++98-compat"
70 block_pool (std::size_t blocks, std::size_t block_size_bytes,
void* addr,
82 std::size_t block_size_bytes,
void* addr, std::size_t bytes);
137 void* addr, std::size_t bytes)
noexcept;
156 do_allocate (std::size_t bytes, std::size_t alignment)
override;
168 std::size_t alignment)
noexcept override;
202 void* pool_addr_ =
nullptr;
207 void*
volatile first_ =
nullptr;
212 std::size_t blocks_ = 0;
217 std::size_t block_size_bytes_ = 0;
222 volatile std::size_t count_ = 0;
243 template <
typename T, std::
size_t N>
254 "Template type T must be large enough to store a pointer.");
315 typename std::aligned_storage<
sizeof (
value_type),
339 template <
typename T,
typename A = os::rtos::memory::allocator<T>>
350 "Template type T must be large enough to store a pointer.");
366 ==
sizeof (
typename allocator_traits::value_type),
367 "The allocator must be parametrised with a type of same size.");
458 : rtos::memory::memory_resource{ name }
463 std::size_t block_size_bytes,
void* addr,
465 :
block_pool{ nullptr, blocks, block_size_bytes, addr, bytes }
470 std::size_t block_size_bytes,
void* addr,
472 : rtos::memory::memory_resource{ name }
475 block_size_bytes, addr, bytes,
this, this->name ());
482 template <
typename T, std::
size_t N>
488 template <
typename T, std::
size_t N>
493 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
499 template <
typename T, std::
size_t N>
502 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
507 template <
typename T,
typename A>
514 template <
typename T,
typename A>
516 const char* name, std::size_t blocks,
const allocator_type& allocator)
519 trace::printf (
"%s(%u,%p) @%p %s\n", __func__, blocks, &allocator,
this,
526 void* addr = allocator_->allocate (blocks);
536 template <
typename T,
typename A>
539 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
542 if (allocator_ !=
nullptr)
544 allocator_->deallocate (
545 static_cast<typename allocator_traits::pointer
> (pool_addr_),
549 allocator_ =
nullptr;
558#pragma GCC diagnostic pop
Memory resource managing a dynamically allocated pool. of same size blocks of type T.
A allocator_type
Standard allocator type definition.
T value_type
Standard allocator type definition.
virtual ~block_pool_typed_allocated() override
Destruct the memory resource object instance.
block_pool_typed_allocated(std::size_t blocks, const allocator_type &allocator=allocator_type())
Construct a memory resource object instance.
std::allocator_traits< A > allocator_traits
Standard allocator traits definition.
Memory resource managing an internal pool. of same size blocks of type T.
block_pool_typed_inclusive(void)
Construct a memory resource object instance.
T value_type
Standard allocator type definition.
static const std::size_t blocks
Local constant based on template definition.
virtual ~block_pool_typed_inclusive() override
Destruct the memory resource object instance.
Memory resource managing a pool of same size blocks, using an existing arena.
block_pool(std::size_t blocks, std::size_t block_size_bytes, void *addr, std::size_t bytes)
Construct a memory resource object instance.
virtual void * do_allocate(std::size_t bytes, std::size_t alignment) override
Implementation of the memory allocator.
virtual std::size_t do_max_size(void) const noexcept override
Implementation of the function to get max size.
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.
virtual void do_deallocate(void *addr, std::size_t bytes, std::size_t alignment) noexcept override
Implementation of the memory deallocator.
void internal_reset_(void) noexcept
Internal function to reset the memory resource object.
virtual ~block_pool() override
Destruct the memory resource object instance.
virtual void do_reset(void) noexcept override
Implementation of the function to reset the memory manager.
const char * name(void) const
Get object name.
Memory resource manager (abstract class).
int printf(const char *format,...)
Write a formatted string to the trace device.
void __throw_bad_alloc(void)
Single file µOS++ RTOS definitions.