28#ifndef CMSIS_PLUS_RTOS_OS_MQUEUE_H_
29#define CMSIS_PLUS_RTOS_OS_MQUEUE_H_
33#if defined(__cplusplus)
44#pragma GCC diagnostic push
47#pragma clang diagnostic ignored "-Wc++98-compat"
48#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
60#pragma GCC diagnostic push
61#pragma GCC diagnostic ignored "-Wpadded"
83#if defined(OS_BOOL_RTOS_MESSAGE_QUEUE_SIZE_16BITS)
234 template<
typename T, std::
size_t msgs, std::
size_t msg_size_
bytes>
238 T
queue[(msgs * msg_size_bytes +
sizeof(T) - 1) /
sizeof(T)];
251 constexpr std::size_t
253 std::size_t msg_size_bytes)
256 return (msgs * ((msg_size_bytes + (
sizeof(T) - 1)) & ~(
sizeof(T) - 1)))
258 + ((2 * msgs *
sizeof(
index_t) + (
sizeof(T) - 1))
261 + ((msgs *
sizeof(
priority_t) + (
sizeof(T) - 1))
294 std::size_t msg_size_bytes,
const attributes& attr =
420 timed_send (
const void* msg, std::size_t nbytes,
575 internal_construct_ (std::size_t msgs, std::size_t msg_size_bytes,
576 const attributes& attr,
void* queue_address,
577 std::size_t queue_size_bytes);
587 internal_init_ (
void);
589#if !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE)
601 internal_try_send_ (
const void* msg, std::size_t nbytes,
615 internal_try_receive_ (
void* msg, std::size_t nbytes,
priority_t* mprio);
639#if !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE)
651 clock* clock_ =
nullptr;
658 volatile index_t* prev_array_ =
nullptr;
662 volatile index_t* next_array_ =
nullptr;
677 void*
volatile first_free_ =
nullptr;
684 void* queue_addr_ =
nullptr;
689 void* allocated_queue_addr_ =
nullptr;
693 const void* allocator_ =
nullptr;
695#if defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE)
696 friend class port::message_queue;
697 os_mqueue_port_data_t port_;
704 std::size_t queue_size_bytes_ = 0;
708 std::size_t allocated_queue_size_elements_ = 0;
723#if !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE)
747 template<
typename Allocator = memory::allocator<
void*>>
785 std::size_t msg_size_bytes,
828 template<
typename T,
typename Allocator = memory::allocator<
void*>>
1039 template<
typename T, std::
size_t N>
1255#pragma GCC diagnostic pop
1285 return this == &rhs;
1321 return msg_size_bytes_;
1376 template<
typename Allocator>
1379 std::size_t msgs, std::size_t msg_size_bytes,
const attributes& attr,
1382 {
nullptr, msgs, msg_size_bytes, attr, allocator }
1413 template<
typename Allocator>
1415 const char* name, std::size_t msgs, std::size_t msg_size_bytes,
1420#if defined(OS_TRACE_RTOS_MQUEUE)
1421 trace::printf (
"%s() @%p %s %d %d\n", __func__,
this, this->name (),
1422 msgs, msg_size_bytes);
1425 if (attr.mq_queue_address !=
nullptr)
1428 internal_construct_ (msgs, msg_size_bytes, attr,
nullptr, 0);
1432 allocator_ = &allocator;
1436 allocated_queue_size_elements_ = (compute_allocated_size_bytes<
1437 typename allocator_type::value_type> (msgs, msg_size_bytes)
1438 +
sizeof(
typename allocator_type::value_type) - 1)
1439 /
sizeof(
typename allocator_type::value_type);
1441 allocated_queue_addr_ =
1442 const_cast<allocator_type&
> (allocator).allocate (
1443 allocated_queue_size_elements_);
1445 internal_construct_ (
1449 allocated_queue_addr_,
1450 allocated_queue_size_elements_
1451 *
sizeof(
typename allocator_type::value_type));
1469 template<
typename Allocator>
1472#if defined(OS_TRACE_RTOS_MQUEUE)
1475 typedef typename std::allocator_traits<allocator_type>::pointer pointer;
1477 if (allocated_queue_addr_ !=
nullptr)
1479 static_cast<allocator_type*
> (
const_cast<void*
> (allocator_))->deallocate (
1480 static_cast<pointer
> (allocated_queue_addr_),
1481 allocated_queue_size_elements_);
1483 allocated_queue_addr_ =
nullptr;
1518 template<
typename T,
typename Allocator>
1524 { msgs,
sizeof(
value_type), attr, allocator }
1558 template<
typename T,
typename Allocator>
1561 const char* name, std::size_t msgs,
1586 template<
typename T,
typename Allocator>
1599 template<
typename T,
typename Allocator>
1605 reinterpret_cast<const char*
> (msg),
sizeof(
value_type), mprio);
1615 template<
typename T,
typename Allocator>
1621 reinterpret_cast<const char*
> (msg),
sizeof(
value_type), mprio);
1631 template<
typename T,
typename Allocator>
1638 reinterpret_cast<const char*
> (msg),
sizeof(
value_type), timeout,
1649 template<
typename T,
typename Allocator>
1655 reinterpret_cast<char*
> (msg),
sizeof(
value_type), mprio);
1665 template<
typename T,
typename Allocator>
1671 reinterpret_cast<char*
> (msg),
sizeof(
value_type), mprio);
1681 template<
typename T,
typename Allocator>
1688 reinterpret_cast<char*
> (msg),
sizeof(
value_type), timeout, mprio);
1727 template<
typename T, std::
size_t N>
1771 template<
typename T, std::
size_t N>
1776 static_assert(
sizeof(T) >=
sizeof(
void*),
"Messages of message_queue need to have at least the size of a pointer");
1795 template<
typename T, std::
size_t N>
1808 template<
typename T, std::
size_t N>
1824 template<
typename T, std::
size_t N>
1840 template<
typename T, std::
size_t N>
1857 template<
typename T, std::
size_t N>
1873 template<
typename T, std::
size_t N>
1889 template<
typename T, std::
size_t N>
1902#pragma GCC diagnostic pop
Base class for attributes.
Base class for named system objects.
const char * name(void) const
Get object name.
Priority ordered list of threads.
Standard allocator based on the RTOS system default memory manager.
Storage for a static message queue.
T prios[(msgs *sizeof(priority_t)+sizeof(T) - 1)/sizeof(T)]
T queue[(msgs *msg_size_bytes+sizeof(T) - 1)/sizeof(T)]
T links[((2 *msgs) *sizeof(index_t)+sizeof(T) - 1)/sizeof(T)]
Message queue attributes.
attributes(attributes &&)=default
attributes(const attributes &)=default
constexpr attributes()
Construct a message queue attributes object instance.
void * mq_queue_address
Address of the user defined storage for the message queue.
std::size_t mq_queue_size_bytes
Size of the user defined storage for the message queue.
attributes & operator=(const attributes &)=default
~attributes()=default
Destruct the message queue attributes object instance.
Template of a POSIX compliant message queue with allocator.
message_queue_allocated(std::size_t msgs, std::size_t msg_size_bytes, const attributes &attr=initializer, const allocator_type &allocator=allocator_type())
Construct a message queue object instance.
message_queue_allocated(const char *name, std::size_t msgs, std::size_t msg_size_bytes, const attributes &attr=initializer, const allocator_type &allocator=allocator_type())
Construct a named message queue object instance.
virtual ~message_queue_allocated() override
Destruct the message queue.
Allocator allocator_type
Standard allocator type definition.
Template of a POSIX compliant message queue with message type and local storage.
T value_type
Local type of message.
result_t send(const value_type *msg, priority_t mprio=default_priority)
Send a typed message to the queue.
virtual ~message_queue_inclusive() override
Destruct the typed message queue object instance.
result_t try_send(const value_type *msg, priority_t mprio=default_priority)
Try to send a typed message to the queue.
result_t timed_send(const value_type *msg, clock::duration_t timeout, priority_t mprio=default_priority)
Send a typed message to the queue with timeout.
message_queue_inclusive(const attributes &attr=initializer)
Construct a typed message queue object instance.
static const std::size_t msgs
Local constant based on template definition.
result_t receive(value_type *msg, priority_t *mprio=nullptr)
Receive a typed message from the queue.
result_t timed_receive(value_type *msg, clock::duration_t timeout, priority_t *mprio=nullptr)
Receive a typed message from the queue with timeout.
result_t try_receive(value_type *msg, priority_t *mprio=nullptr)
Try to receive a typed message from the queue.
Template of a POSIX compliant message queue with message type and allocator.
T value_type
Standard allocator type definition.
result_t send(const value_type *msg, message_queue::priority_t mprio=message_queue::default_priority)
Send a typed message to the queue.
result_t try_send(const value_type *msg, message_queue::priority_t mprio=message_queue::default_priority)
Try to send a typed message to the queue.
Allocator allocator_type
Standard allocator type definition.
result_t try_receive(value_type *msg, message_queue::priority_t *mprio=nullptr)
Try to receive a typed message from the queue.
result_t receive(value_type *msg, message_queue::priority_t *mprio=nullptr)
Receive a typed message from the queue.
result_t timed_receive(value_type *msg, clock::duration_t timeout, message_queue::priority_t *mprio=nullptr)
Receive a typed message from the queue with timeout.
message_queue_typed(std::size_t msgs, const message_queue::attributes &attr=message_queue::initializer, const allocator_type &allocator=allocator_type())
Construct a typed message queue object instance.
virtual ~message_queue_typed() override
Destruct the typed message queue object instance.
result_t timed_send(const value_type *msg, clock::duration_t timeout, message_queue::priority_t mprio=message_queue::default_priority)
Send a typed message to the queue with timeout.
POSIX compliant message queue, using the default RTOS allocator.
bool empty(void) const
Check if the queue is empty.
result_t receive(void *msg, std::size_t nbytes, priority_t *mprio=nullptr)
Receive a message from the queue.
result_t reset(void)
Reset the message queue.
result_t try_send(const void *msg, std::size_t nbytes, priority_t mprio=default_priority)
Try to send a message to the queue.
result_t try_receive(void *msg, std::size_t nbytes, priority_t *mprio=nullptr)
Try to receive a message from the queue.
result_t send(const void *msg, std::size_t nbytes, priority_t mprio=default_priority)
Send a message to the queue.
virtual ~message_queue()
Destruct the message queue object instance.
result_t timed_receive(void *msg, std::size_t nbytes, clock::duration_t timeout, priority_t *mprio=nullptr)
Receive a message from the queue with timeout.
std::size_t capacity(void) const
Get queue capacity.
std::size_t msg_size(void) const
Get message size.
result_t timed_send(const void *msg, std::size_t nbytes, clock::duration_t timeout, priority_t mprio=default_priority)
Send a message to the queue with timeout.
constexpr std::size_t compute_allocated_size_bytes(std::size_t msgs, std::size_t msg_size_bytes)
Calculator for queue storage requirements.
bool full(void) const
Check if the queue is full.
std::size_t length(void) const
Get queue length.
bool operator==(const message_queue &rhs) const
Compare memory queues.
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.
static constexpr msg_size_t max_msg_size
Maximum message size.
static constexpr priority_t max_priority
Maximum message priority.
uint8_t priority_t
Type of message priority storage.
message_queue::size_t index_t
Type of list index storage.
static constexpr priority_t default_priority
Default message priority.
static const attributes initializer
Default message queue initialiser.
uint8_t size_t
Type of a queue size storage.
memory::allocator< thread::stack::allocation_element_t > allocator_type
Default RTOS allocator.
uint16_t msg_size_t
Type of message size storage.
static constexpr index_t no_index
Index value to represent an illegal index.
static constexpr message_queue::size_t max_size
Maximum queue size.
uint32_t result_t
Type of values returned by RTOS functions.