13#if defined(OS_USE_OS_APP_CONFIG_H)
14#include <cmsis-plus/os-app-config.h>
23#pragma clang diagnostic ignored "-Wc++98-compat"
40#pragma GCC diagnostic push
42#pragma clang diagnostic ignored "-Wunused-parameter"
43#elif defined(__GNUC__)
44#pragma GCC diagnostic ignored "-Wunused-parameter"
50 assert(bytes <= block_size_bytes_);
52 if (first_ ==
nullptr)
57 void* p =
static_cast<void*
> (first_);
58 first_ = *(
static_cast<void**
> (first_));
60#pragma GCC diagnostic push
62#pragma clang diagnostic ignored "-Wdeprecated-volatile"
63#elif defined(__GNUC__)
64#pragma GCC diagnostic ignored "-Wvolatile"
67#pragma GCC diagnostic pop
73#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
74 trace::printf (
"%s(%u,%u)=%p,%u @%p %s\n", __func__, bytes, alignment, p,
75 block_size_bytes_,
this,
name ());
83 std::size_t alignment)
noexcept
85#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
86 trace::printf (
"%s(%p,%u,%u) @%p %s\n", __func__, addr, bytes, alignment,
90 if ((addr < pool_addr_)
92 >= (
static_cast<char*
> (pool_addr_) + blocks_ * block_size_bytes_)))
103 *(
static_cast<void**
> (addr)) = first_;
108#pragma GCC diagnostic push
109#if defined(__clang__)
110#pragma clang diagnostic ignored "-Wdeprecated-volatile"
111#elif defined(__GNUC__)
112#pragma GCC diagnostic ignored "-Wvolatile"
115#pragma GCC diagnostic pop
119 internal_decrease_allocated_statistics (block_size_bytes_);
122#pragma GCC diagnostic push
127 return block_size_bytes_ * blocks_;
133#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
141 std::size_t block_size_bytes,
void* addr,
142 std::size_t bytes)
noexcept
148 assert(block_size_bytes_ >=
sizeof(
void*));
150 assert(addr !=
nullptr);
153 std::size_t align_sz = bytes;
157 res = std::align (
alignof(
void*), blocks * block_size_bytes_, pool_addr_,
163 assert(res !=
nullptr);
169 total_bytes_ = blocks_ * block_size_bytes_;
180 char* p =
static_cast<char*
> (pool_addr_);
181 for (std::size_t i = 1; i < blocks_; ++i)
184 char* pn = p + block_size_bytes_;
187 *(
static_cast<void**
> (
static_cast<void*
> (p))) = pn;
193 *(
static_cast<void**
> (
static_cast<void*
> (p))) =
nullptr;
199 allocated_bytes_ = 0;
200 max_allocated_bytes_ = 0;
201 free_bytes_ = total_bytes_;
202 allocated_chunks_ = 0;
203 free_chunks_ = blocks_;
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.
void internal_increase_allocated_statistics(std::size_t bytes) noexcept
Update statistics after allocation.
int printf(const char *format,...)
Write a formatted string to the trace device.
constexpr std::size_t align_size(std::size_t size, std::size_t align) noexcept
Helper function to align size values.
Single file µOS++ RTOS definitions.