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"
183#if defined(OS_TRACE_RTOS_MEMPOOL)
192#if defined(OS_TRACE_RTOS_MEMPOOL)
193 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
229 memory_pool::memory_pool (std::size_t blocks, std::size_t block_size_bytes,
233 {
nullptr, blocks, block_size_bytes, attr, allocator }
266 std::size_t block_size_bytes,
272#if defined(OS_TRACE_RTOS_MEMPOOL)
273 trace::printf (
"%s() @%p %s %u %u\n", __func__,
this, this->name (),
274 blocks, block_size_bytes);
277 if (attr.mp_pool_address !=
nullptr)
280 internal_construct_ (blocks, block_size_bytes, attr,
nullptr, 0);
284 allocator_ = &allocator;
288 allocated_pool_size_elements_ = (compute_allocated_size_bytes<
289 typename allocator_type::value_type> (blocks, block_size_bytes)
290 +
sizeof(
typename allocator_type::value_type) - 1)
291 /
sizeof(
typename allocator_type::value_type);
293 allocated_pool_addr_ =
294 const_cast<allocator_type&
> (allocator).allocate (
295 allocated_pool_size_elements_);
297 internal_construct_ (
301 allocated_pool_addr_,
302 allocated_pool_size_elements_
303 *
sizeof(
typename allocator_type::value_type));
312 memory_pool::internal_construct_ (std::size_t blocks,
313 std::size_t block_size_bytes,
314 const attributes& attr,
316 std::size_t pool_size_bytes)
321#if !defined(OS_USE_RTOS_PORT_MEMORY_POOL)
322 clock_ = attr.clock !=
nullptr ? attr.clock : &
sysclock;
326 assert(blocks_ == blocks);
333 + __SIZEOF_POINTER__ - 1))
337 if (pool_address !=
nullptr)
340 assert(attr.mp_pool_address ==
nullptr);
342 pool_addr_ = pool_address;
343 pool_size_bytes_ = pool_size_bytes;
347 pool_addr_ = attr.mp_pool_address;
348 pool_size_bytes_ = attr.mp_pool_size_bytes;
352 void* p = pool_addr_;
353 std::size_t sz = pool_size_bytes_;
354 pool_addr_ =
static_cast<char*
> (
355 std::align (__SIZEOF_POINTER__,
356 static_cast<std::size_t
>(blocks_ * block_size_bytes_),
360#if defined(OS_TRACE_RTOS_MEMPOOL)
362 blocks_, block_size_bytes_, pool_addr_, pool_size_bytes_);
365 std::size_t storage_size = compute_allocated_size_bytes<void*> (
366 blocks_, block_size_bytes_);
368 if (pool_addr_ !=
nullptr)
405#if defined(OS_TRACE_RTOS_MEMPOOL)
410 assert(list_.empty ());
412 typedef typename std::allocator_traits<allocator_type>::pointer pointer;
414 if (allocated_pool_addr_ !=
nullptr)
417 static_cast<pointer
> (allocated_pool_addr_),
418 allocated_pool_size_elements_);
431 memory_pool::internal_init_ (
void)
436 char* p =
static_cast<char*
> (pool_addr_);
437 for (std::size_t i = 1; i < blocks_; ++i)
440 char* pn = p + block_size_bytes_;
443 *(
static_cast<void**
> (
static_cast<void*
> (p))) = pn;
449 *(
static_cast<void**
> (
static_cast<void*
> (p))) =
nullptr;
462 memory_pool::internal_try_first_ (
void)
464 if (first_ !=
nullptr)
466 void* p =
static_cast<void*
> (first_);
467 first_ = *(
static_cast<void**
> (first_));
469#pragma GCC diagnostic push
470#if defined(__clang__)
471#pragma clang diagnostic ignored "-Wdeprecated-volatile"
472#elif defined(__GNUC__)
473#pragma GCC diagnostic ignored "-Wvolatile"
476#pragma GCC diagnostic pop
510#if defined(OS_TRACE_RTOS_MEMPOOL)
527 p = internal_try_first_ ();
530#if defined(OS_TRACE_RTOS_MEMPOOL)
552 p = internal_try_first_ ();
555#if defined(OS_TRACE_RTOS_MEMPOOL)
563 scheduler::internal_link_node (list_, node);
572 scheduler::internal_unlink_node (node);
576#if defined(OS_TRACE_RTOS_MEMPOOL)
606#if defined(OS_TRACE_RTOS_MEMPOOL)
611 assert(port::interrupts::is_priority_valid ());
618 p = internal_try_first_ ();
622#if defined(OS_TRACE_RTOS_MEMPOOL)
671#if defined(OS_TRACE_RTOS_MEMPOOL)
672#pragma GCC diagnostic push
673#if defined(__clang__)
674#elif defined(__GNUC__)
675#pragma GCC diagnostic ignored "-Wuseless-cast"
678 static_cast<unsigned int> (timeout),
this,
name ());
679#pragma GCC diagnostic pop
695 p = internal_try_first_ ();
698#if defined(OS_TRACE_RTOS_MEMPOOL)
719 { timeout_timestamp, crt_thread };
727 p = internal_try_first_ ();
730#if defined(OS_TRACE_RTOS_MEMPOOL)
739 scheduler::internal_link_node (list_, node, clock_list,
750 scheduler::internal_unlink_node (node, timeout_node);
754#if defined(OS_TRACE_RTOS_MEMPOOL)
760 if (clock_->steady_now () >= timeout_timestamp)
762#if defined(OS_TRACE_RTOS_MEMPOOL)
785#if defined(OS_TRACE_RTOS_MEMPOOL)
790 assert(port::interrupts::is_priority_valid ());
793 if ((block < pool_addr_)
795 >= (
static_cast<char*
> (pool_addr_) + blocks_ * block_size_bytes_)))
797#if defined(OS_TRACE_RTOS_MEMPOOL)
798 trace::printf (
"%s(%p) EINVAL @%p %s\n", __func__, block,
this,
813 *(
static_cast<void**
> (block)) = first_;
818#pragma GCC diagnostic push
819#if defined(__clang__)
820#pragma clang diagnostic ignored "-Wdeprecated-volatile"
821#elif defined(__GNUC__)
822#pragma GCC diagnostic ignored "-Wvolatile"
825#pragma GCC diagnostic pop
845#if defined(OS_TRACE_RTOS_MEMPOOL)
Ordered list of time stamp nodes.
const char * name(void) const
Get object name.
Double linked list node, with time stamp and thread.
Double linked list node, with thread reference.
Interrupts critical section RAII helper.
Standard allocator based on the RTOS system default memory manager.
void deallocate(value_type *addr, std::size_t elements) noexcept
Deallocate the number of memory blocks of type value_type.
Synchronised memory pool, using the default RTOS allocator.
memory_pool(std::size_t blocks, std::size_t block_size_bytes, const attributes &attr=initializer, const allocator_type &allocator=allocator_type())
Construct a memory pool object instance.
void * timed_alloc(clock::duration_t timeout)
Allocate a memory block with timeout.
void * try_alloc(void)
Try to allocate a memory block.
void * alloc(void)
Allocate a memory block.
result_t free(void *block)
Free the memory block.
result_t reset(void)
Reset the memory pool.
virtual ~memory_pool()
Destruct the memory pool object instance.
POSIX compliant thread, using the default RTOS allocator.
int printf(const char *format,...)
Write a formatted string to the trace device.
port::clock::duration_t duration_t
Type of variables holding clock durations.
port::clock::timestamp_t timestamp_t
Type of variables holding clock time stamps.
clock_systick sysclock
The system clock object instance.
uint16_t size_t
Type of memory pool size storage.
static const attributes initializer
Default memory pool initialiser.
bool in_handler_mode(void)
Check if the CPU is in handler mode.
@ ok
Function completed; no errors or events occurred.
bool locked(void)
Check if the scheduler is locked.
thread & thread(void)
Get the current running thread.
uint32_t result_t
Type of values returned by RTOS functions.
#define os_assert_throw(__e, __er)
Assert or throw a system error exception.
#define os_assert_err(__e, __er)
Assert or return an error.
Single file µOS++ RTOS definitions.