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"
187#if defined(OS_TRACE_RTOS_MEMPOOL)
188 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
194#if defined(OS_TRACE_RTOS_MEMPOOL)
195 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
234 :
memory_pool{ nullptr, blocks, block_size_bytes, attr, allocator }
267 std::size_t block_size_bytes,
270 : object_named_system{ name }
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);
280 internal_construct_ (blocks, block_size_bytes, attr,
nullptr, 0);
284 allocator_ = &allocator;
288 allocated_pool_size_elements_
297 allocated_pool_size_elements_);
299 internal_construct_ (
300 blocks, block_size_bytes, attr, allocated_pool_addr_,
301 allocated_pool_size_elements_
311 memory_pool::internal_construct_ (std::size_t blocks,
312 std::size_t block_size_bytes,
313 const attributes& attr,
315 std::size_t pool_size_bytes)
320#if !defined(OS_USE_RTOS_PORT_MEMORY_POOL)
321 clock_ = attr.clock !=
nullptr ? attr.clock : &
sysclock;
325 assert (blocks_ == blocks);
326 assert (blocks_ > 0);
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*
> (std::align (
356 static_cast<std::size_t
> (blocks_ * block_size_bytes_), p, sz));
358#if defined(OS_TRACE_RTOS_MEMPOOL)
360 blocks_, block_size_bytes_, pool_addr_, pool_size_bytes_);
363 std::size_t storage_size
364 = compute_allocated_size_bytes<void*> (blocks_, block_size_bytes_);
366 if (pool_addr_ !=
nullptr)
402#if defined(OS_TRACE_RTOS_MEMPOOL)
407 assert (list_.empty ());
409 typedef typename std::allocator_traits<allocator_type>::pointer pointer;
411 if (allocated_pool_addr_ !=
nullptr)
414 ->
deallocate (
static_cast<pointer
> (allocated_pool_addr_),
415 allocated_pool_size_elements_);
428 memory_pool::internal_init_ (
void)
433#pragma GCC diagnostic push
434#if defined(__clang__)
435#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
437 char* p =
static_cast<char*
> (pool_addr_);
438 for (std::size_t i = 1; i < blocks_; ++i)
441 char* pn = p + block_size_bytes_;
444 *(
static_cast<void**
> (
static_cast<void*
> (p))) = pn;
448#pragma GCC diagnostic pop
451 *(
static_cast<void**
> (
static_cast<void*
> (p))) =
nullptr;
464 memory_pool::internal_try_first_ (
void)
466 if (first_ !=
nullptr)
468 void* p =
static_cast<void*
> (first_);
469 first_ = *(
static_cast<void**
> (first_));
471#pragma GCC diagnostic push
472#if defined(__clang__)
473#pragma clang diagnostic ignored "-Wdeprecated-volatile"
474#elif defined(__GNUC__)
475#pragma GCC diagnostic ignored "-Wvolatile"
478#pragma GCC diagnostic pop
512#if defined(OS_TRACE_RTOS_MEMPOOL)
529 p = internal_try_first_ ();
532#if defined(OS_TRACE_RTOS_MEMPOOL)
553 p = internal_try_first_ ();
556#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)
726 p = internal_try_first_ ();
729#if defined(OS_TRACE_RTOS_MEMPOOL)
737 scheduler::internal_link_node (list_, node, clock_list,
748 scheduler::internal_unlink_node (node, timeout_node);
752#if defined(OS_TRACE_RTOS_MEMPOOL)
758 if (clock_->steady_now () >= timeout_timestamp)
760#if defined(OS_TRACE_RTOS_MEMPOOL)
783#if defined(OS_TRACE_RTOS_MEMPOOL)
788 assert (port::interrupts::is_priority_valid ());
791#pragma GCC diagnostic push
792#if defined(__clang__)
793#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
795 if ((block < pool_addr_)
796 || (block >= (
static_cast<char*
> (pool_addr_)
797 + blocks_ * block_size_bytes_)))
799#if defined(OS_TRACE_RTOS_MEMPOOL)
800 trace::printf (
"%s(%p) EINVAL @%p %s\n", __func__, block,
this,
805#pragma GCC diagnostic pop
816 *(
static_cast<void**
> (block)) = first_;
821#pragma GCC diagnostic push
822#if defined(__clang__)
823#pragma clang diagnostic ignored "-Wdeprecated-volatile"
824#elif defined(__GNUC__)
825#pragma GCC diagnostic ignored "-Wvolatile"
828#pragma GCC diagnostic pop
848#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.
T value_type
Type of elements to be allocated.
void * mp_pool_address
Address of the user defined storage for the memory pool.
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.
constexpr std::size_t compute_allocated_size_bytes(std::size_t blocks, std::size_t block_size_bytes)
Calculator for pool storage requirements.
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.