28 #ifndef CMSIS_PLUS_RTOS_OS_MQUEUE_H_ 29 #define CMSIS_PLUS_RTOS_OS_MQUEUE_H_ 33 #if defined(__cplusplus) 49 #pragma GCC diagnostic push 50 #pragma GCC diagnostic ignored "-Wpadded" 72 #if defined(OS_BOOL_RTOS_MESSAGE_QUEUE_SIZE_16BITS) 73 using size_t = uint16_t;
75 using size_t = uint8_t;
223 template<
typename T, std::
size_t msgs, std::
size_t msg_size_bytes>
227 T queue[(msgs * msg_size_bytes +
sizeof(T) - 1) /
sizeof(T)];
228 T links[((2 * msgs) *
sizeof(
index_t) +
sizeof(T) - 1) /
sizeof(T)];
229 T prios[(msgs *
sizeof(
priority_t) +
sizeof(T) - 1) /
sizeof(T)];
240 constexpr std::size_t
242 std::size_t msg_size_bytes)
245 return (msgs * ((msg_size_bytes + (
sizeof(T) - 1)) & ~(
sizeof(T) - 1)))
247 + ((2 * msgs *
sizeof(
index_t) + (
sizeof(T) - 1))
250 + ((msgs *
sizeof(
priority_t) + (
sizeof(T) - 1))
283 std::size_t msg_size_bytes,
const attributes& attr =
409 timed_send (
const void* msg, std::size_t nbytes,
564 internal_construct_ (std::size_t msgs, std::size_t msg_size_bytes,
566 std::size_t queue_size_bytes);
576 internal_init_ (
void);
578 #if !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE) 590 internal_try_send_ (
const void* msg, std::size_t nbytes,
604 internal_try_receive_ (
void* msg, std::size_t nbytes,
priority_t* mprio);
628 #if !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE) 640 clock* clock_ =
nullptr;
647 volatile index_t* prev_array_ =
nullptr;
651 volatile index_t* next_array_ =
nullptr;
666 void*
volatile first_free_ =
nullptr;
673 void* queue_addr_ =
nullptr;
678 void* allocated_queue_addr_ =
nullptr;
682 const void* allocator_ =
nullptr;
684 #if defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE) 685 friend class port::message_queue;
686 os_mqueue_port_data_t port_;
693 std::size_t queue_size_bytes_ = 0;
697 std::size_t allocated_queue_size_elements_ = 0;
712 #if !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE) 736 template<
typename Allocator = memory::allocator<
void*>>
774 std::size_t msg_size_bytes,
817 template<
typename T,
typename Allocator = memory::allocator<
void*>>
1028 template<
typename T, std::
size_t N>
1041 static const std::size_t msgs = N;
1244 #pragma GCC diagnostic pop 1274 return this == &rhs;
1313 return msg_size_bytes_;
1370 template<
typename Allocator>
1373 std::size_t msgs, std::size_t msg_size_bytes,
const attributes& attr,
1376 {
nullptr, msgs, msg_size_bytes, attr, allocator }
1407 template<
typename Allocator>
1409 const char*
name, std::size_t msgs, std::size_t msg_size_bytes,
1414 #if defined(OS_TRACE_RTOS_MQUEUE) 1416 msgs, msg_size_bytes);
1419 if (attr.mq_queue_address !=
nullptr)
1422 internal_construct_ (msgs, msg_size_bytes, attr,
nullptr, 0);
1435 allocated_queue_addr_ =
1437 allocated_queue_size_elements_);
1439 internal_construct_ (
1443 allocated_queue_addr_,
1444 allocated_queue_size_elements_
1463 template<
typename Allocator>
1466 #if defined(OS_TRACE_RTOS_MQUEUE) 1469 typedef typename std::allocator_traits<allocator_type>::pointer pointer;
1471 if (allocated_queue_addr_ !=
nullptr)
1474 static_cast<pointer> (allocated_queue_addr_),
1475 allocated_queue_size_elements_);
1477 allocated_queue_addr_ =
nullptr;
1512 template<
typename T,
typename Allocator>
1518 { msgs,
sizeof(
value_type), attr, allocator }
1552 template<
typename T,
typename Allocator>
1555 const char*
name, std::size_t msgs,
1580 template<
typename T,
typename Allocator>
1593 template<
typename T,
typename Allocator>
1599 reinterpret_cast<const char*> (msg),
sizeof(
value_type), mprio);
1609 template<
typename T,
typename Allocator>
1615 reinterpret_cast<const char*> (msg),
sizeof(
value_type), mprio);
1625 template<
typename T,
typename Allocator>
1632 reinterpret_cast<const char*> (msg),
sizeof(
value_type), timeout,
1643 template<
typename T,
typename Allocator>
1649 reinterpret_cast<char*> (msg),
sizeof(
value_type), mprio);
1659 template<
typename T,
typename Allocator>
1665 reinterpret_cast<char*> (msg),
sizeof(
value_type), mprio);
1675 template<
typename T,
typename Allocator>
1682 reinterpret_cast<char*> (msg),
sizeof(
value_type), timeout, mprio);
1721 template<
typename T, std::
size_t N>
1765 template<
typename T, std::
size_t N>
1770 static_assert(
sizeof(T) >=
sizeof(
void*),
"Messages of message_queue need to have at least the size of a pointer");
1772 internal_construct_ (msgs,
sizeof(
value_type), attr, &arena_,
1789 template<
typename T, std::
size_t N>
1802 template<
typename T, std::
size_t N>
1818 template<
typename T, std::
size_t N>
1834 template<
typename T, std::
size_t N>
1851 template<
typename T, std::
size_t N>
1867 template<
typename T, std::
size_t N>
1883 template<
typename T, std::
size_t N>
message_queue::size_t index_t
Type of list index storage.
virtual ~message_queue()
Destruct the message queue object instance.
attributes & operator=(const attributes &)=default
message_queue_inclusive(const attributes &attr=initializer)
Construct a typed message queue object instance.
result_t reset(void)
Reset the message queue.
result_t try_receive(value_type *msg, priority_t *mprio=nullptr)
Try to receive a typed message from the queue.
result_t receive(value_type *msg, priority_t *mprio=nullptr)
Receive a typed message from the queue.
result_t try_send(const value_type *msg, priority_t mprio=default_priority)
Try to send a typed message to the queue.
void deallocate(value_type *addr, std::size_t elements) noexcept
Deallocate the number of memory blocks of type value_type.
result_t try_send(const void *msg, std::size_t nbytes, priority_t mprio=default_priority)
Try to send a message to the queue.
Priority ordered list of threads.
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.
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.
result_t receive(void *msg, std::size_t nbytes, priority_t *mprio=nullptr)
Receive a message from the queue.
uint16_t msg_size_t
Type of message size storage.
Template of a POSIX compliant message queue with message type and allocator.
result_t try_receive(value_type *msg, message_queue::priority_t *mprio=nullptr)
Try to receive a typed message from the queue.
static constexpr message_queue::size_t max_size
Maximum queue size.
Base class for attributes.
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.
constexpr std::size_t compute_allocated_size_bytes(std::size_t msgs, std::size_t msg_size_bytes)
Calculator for queue storage requirements.
result_t try_receive(void *msg, std::size_t nbytes, priority_t *mprio=nullptr)
Try to receive a message from the queue.
T value_type
Local type of message.
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.
bool full(void) const
Check if the queue is full.
bool empty(void) const
Check if the queue is empty.
uint8_t size_t
Type of a queue size storage.
static constexpr priority_t max_priority
Maximum message priority.
const char * name(void) const
Get object name.
Base class for named system objects.
uint8_t priority_t
Type of message priority storage.
virtual ~message_queue_inclusive()
Destruct the typed message queue object instance.
Template of a POSIX compliant message queue with message type and local storage.
port::clock::duration_t duration_t
Type of variables holding clock durations.
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.
std::size_t mq_queue_size_bytes
Size of the user defined storage for the message queue.
virtual ~message_queue_allocated()
Destruct the message queue.
int printf(const char *format,...)
Write a formatted string to the trace device.
result_t send(const value_type *msg, message_queue::priority_t mprio=message_queue::default_priority)
Send a typed message to the queue.
T value_type
Standard allocator type definition.
result_t send(const void *msg, std::size_t nbytes, priority_t mprio=default_priority)
Send a message to the queue.
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.
static constexpr index_t no_index
Index value to represent an illegal index.
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.
static const attributes initializer
Default message queue initialiser.
T value_type
Type of elements to be allocated.
static constexpr priority_t default_priority
Default message priority.
bool operator==(const message_queue &rhs) const
Compare memory queues.
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 send(const value_type *msg, priority_t mprio=default_priority)
Send a typed message to the queue.
static constexpr msg_size_t max_msg_size
Maximum message size.
std::size_t msg_size(void) const
Get message size.
constexpr attributes()
Construct a message queue attributes object instance.
std::size_t length(void) const
Get queue length.
virtual ~message_queue_typed()
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.
Storage for a static message queue.
result_t receive(value_type *msg, message_queue::priority_t *mprio=nullptr)
Receive a typed message from the queue.
~attributes()=default
Destruct the message queue attributes object instance.
uint32_t result_t
Type of values returned by RTOS functions.
void * mq_queue_address
Address of the user defined storage for the message queue.
Message queue attributes.
message_queue(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.
Template of a POSIX compliant message queue with allocator.
std::size_t capacity(void) const
Get queue capacity.
allocator_stateless_default_resource< T > allocator
Type of allocator used by the system objects. Must be stateless.
Standard allocator based on the RTOS system default memory manager.
POSIX compliant message queue, using the default RTOS allocator.