12#if defined(OS_USE_OS_APP_CONFIG_H)
13#include <cmsis-plus/os-app-config.h>
22#pragma clang diagnostic ignored "-Wc++98-compat"
39#pragma GCC diagnostic push
41#pragma clang diagnostic ignored "-Wunused-parameter"
42#elif defined(__GNUC__)
43#pragma GCC diagnostic ignored "-Wunused-parameter"
49 assert (bytes <= block_size_bytes_);
51 if (first_ ==
nullptr)
56 void* p =
static_cast<void*
> (first_);
57 first_ = *(
static_cast<void**
> (first_));
59#pragma GCC diagnostic push
61#pragma clang diagnostic ignored "-Wdeprecated-volatile"
62#elif defined(__GNUC__)
63#pragma GCC diagnostic ignored "-Wvolatile"
66#pragma GCC diagnostic pop
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 ());
82 std::size_t alignment)
noexcept
84#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
85 trace::printf (
"%s(%p,%u,%u) @%p %s\n", __func__, addr, bytes, alignment,
89#pragma GCC diagnostic push
91#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
93 if ((addr < pool_addr_)
94 || (addr >= (
static_cast<char*
> (pool_addr_)
95 + blocks_ * block_size_bytes_)))
100#pragma GCC diagnostic pop
107 *(
static_cast<void**
> (addr)) = first_;
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"
119#pragma GCC diagnostic pop
123 internal_decrease_allocated_statistics (block_size_bytes_);
126#pragma GCC diagnostic push
131 return block_size_bytes_ * blocks_;
137#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
145 std::size_t block_size_bytes,
void* addr,
146 std::size_t bytes)
noexcept
152 assert (block_size_bytes_ >=
sizeof (
void*));
154 assert (addr !=
nullptr);
157 std::size_t align_sz = bytes;
161 res = std::align (
alignof (
void*), blocks * block_size_bytes_,
162 pool_addr_, align_sz);
167 assert (res !=
nullptr);
173 total_bytes_ = blocks_ * block_size_bytes_;
184#pragma GCC diagnostic push
185#if defined(__clang__)
186#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
188 char* p =
static_cast<char*
> (pool_addr_);
189 for (std::size_t i = 1; i < blocks_; ++i)
192 char* pn = p + block_size_bytes_;
195 *(
static_cast<void**
> (
static_cast<void*
> (p))) = pn;
199#pragma GCC diagnostic pop
202 *(
static_cast<void**
> (
static_cast<void*
> (p))) =
nullptr;
208 allocated_bytes_ = 0;
209 max_allocated_bytes_ = 0;
210 free_bytes_ = total_bytes_;
211 allocated_chunks_ = 0;
212 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.