28#ifndef CMSIS_PLUS_MEMORY_BLOCK_POOL_H_
29#define CMSIS_PLUS_MEMORY_BLOCK_POOL_H_
33#if defined(__cplusplus)
41#pragma GCC diagnostic push
44#pragma clang diagnostic ignored "-Wc++98-compat"
88 block_pool (std::size_t blocks, std::size_t block_size_bytes,
void* addr,
100 std::size_t block_size_bytes,
void* addr, std::size_t bytes);
156 void* addr, std::size_t bytes)
noexcept;
175 do_allocate (std::size_t bytes, std::size_t alignment)
override;
186 do_deallocate (
void* addr, std::size_t bytes, std::size_t alignment)
222 void* pool_addr_ =
nullptr;
227 void*
volatile first_ =
nullptr;
232 std::size_t blocks_ = 0;
237 std::size_t block_size_bytes_ = 0;
242 volatile std::size_t count_ = 0;
264 template<
typename T, std::
size_t N>
274 static_assert(
sizeof(
value_type) >=
sizeof(
void*),
275 "Template type T must be large enough to store a pointer.");
361 template<
typename T,
typename A = os::rtos::memory::allocator<T>>
371 static_assert(
sizeof(
value_type) >=
sizeof(
void*),
372 "Template type T must be large enough to store a pointer.");
386 static_assert(
sizeof(
value_type) ==
sizeof(
typename allocator_traits::value_type),
387 "The allocator must be parametrised with a type of same size.");
480 rtos::memory::memory_resource
488 void* addr, std::size_t bytes) :
490 {
nullptr, blocks, block_size_bytes, addr, bytes }
497 std::size_t block_size_bytes,
void* addr,
499 rtos::memory::memory_resource
503 block_size_bytes, addr, bytes,
this, this->name ());
505 internal_construct_ (blocks, block_size_bytes, addr, bytes);
510 template<
typename T, std::
size_t N>
518 template<
typename T, std::
size_t N>
525 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
527 internal_construct_ (blocks,
sizeof(value_type), &arena_[0],
531 template<
typename T, std::
size_t N>
534 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
539 template<
typename T,
typename A>
548 template<
typename T,
typename A>
550 const char* name, std::size_t blocks,
const allocator_type& allocator) :
554 trace::printf (
"%s(%u,%p) @%p %s\n", __func__, blocks, &allocator,
this,
559 static_cast<allocator_type*
> (&
const_cast<allocator_type&
> (allocator));
561 void* addr = allocator_->allocate (blocks);
567 internal_construct_ (blocks,
sizeof(value_type), addr,
568 blocks *
sizeof(value_type));
571 template<
typename T,
typename A>
574 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
577 if (allocator_ !=
nullptr)
579 allocator_->deallocate (
580 static_cast<typename allocator_traits::pointer
> (pool_addr_),
584 allocator_ =
nullptr;
593#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.