µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
os::rtos::message_queue_inclusive< T, N > Class Template Reference

Template of a POSIX compliant message queue with message type and local storage. More...

#include <cmsis-plus/rtos/os.h>

+ Inheritance diagram for os::rtos::message_queue_inclusive< T, N >:

Public Types

using allocator_type = memory::allocator< thread::stack::allocation_element_t >
 Default RTOS allocator.
 
using index_t = message_queue::size_t
 Type of list index storage.
 
using msg_size_t = uint16_t
 Type of message size storage.
 
using priority_t = uint8_t
 Type of message priority storage.
 
using size_t = uint8_t
 Type of a queue size storage.
 
using value_type = T
 Local type of message.
 

Public Member Functions

template<typename T >
constexpr std::size_t compute_allocated_size_bytes (std::size_t msgs, std::size_t msg_size_bytes)
 Calculator for queue storage requirements.
 
Constructors & Destructor
 message_queue_inclusive (const attributes &attr=initializer)
 Construct a typed message queue object instance.
 
 message_queue_inclusive (const char *name, const attributes &attr=initializer)
 Construct a named typed message queue object instance.
 
virtual ~message_queue_inclusive () override
 Destruct the typed message queue object instance.
 
Public Member Functions
result_t send (const value_type *msg, priority_t mprio=default_priority)
 Send a typed message to the queue.
 
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.
 
result_t receive (value_type *msg, priority_t *mprio=nullptr)
 Receive a typed message from the queue.
 
result_t try_receive (value_type *msg, priority_t *mprio=nullptr)
 Try to 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.
 
Operators
bool operator== (const message_queue &rhs) const
 Compare memory queues.
 
Public Member Functions
result_t send (const void *msg, std::size_t nbytes, priority_t mprio=default_priority)
 Send a message to the 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 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 receive (void *msg, std::size_t nbytes, priority_t *mprio=nullptr)
 Receive a message from 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 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 length (void) const
 Get queue length.
 
std::size_t msg_size (void) const
 Get message size.
 
bool empty (void) const
 Check if the queue is empty.
 
bool full (void) const
 Check if the queue is full.
 
result_t reset (void)
 Reset the message queue.
 
Public Member Functions
const char * name (void) const
 Get object name.
 

Static Public Member Functions

Operators
static void * operator new (std::size_t bytes)
 Allocate space for a new object instance using the RTOS system allocator.
 
static void * operator new (std::size_t bytes, void *ptr)
 Emplace a new object instance.
 
static void * operator new[] (std::size_t bytes)
 Allocate space for an array of new object instances using the RTOS system allocator.
 
static void * operator new[] (std::size_t bytes, void *ptr)
 Emplace an array of new object instances.
 
static void operator delete (void *ptr, std::size_t bytes)
 Deallocate the dynamically allocated object instance. using the RTOS system allocator.
 
static void operator delete[] (void *ptr, std::size_t bytes)
 Deallocate the dynamically allocated array of object. instances using the RTOS system allocator.
 

Static Public Attributes

static constexpr priority_t default_priority = 0
 Default message priority.
 
static const attributes initializer
 Default message queue initialiser.
 
static constexpr msg_size_t max_msg_size = 0xFFFF
 Maximum message size.
 
static constexpr priority_t max_priority = 0xFF
 Maximum message priority.
 
static constexpr message_queue::size_t max_size = 0xFF
 Maximum queue size.
 
static const std::size_t msgs = N
 Local constant based on template definition.
 
static constexpr index_t no_index = max_size
 Index value to represent an illegal index.
 

Detailed Description

template<typename T, std::size_t N>
class os::rtos::message_queue_inclusive< T, N >

Template of a POSIX compliant message queue with message type and local storage.

If the queue size is known at compile time and the queue is used for the entire application life cycle, it might be preferred to allocate the queue storage statically inside the queue instance.

For convenience, message_queue_inclusive are also typed, so the message size is handled automatically.

Example
// Define the message type.
typedef struct {
uint32_t id;
} msg_t;
// Define the queue size.
constexpr uint32_t queue_size = 5;
// The queue storage is allocated statically inside this instance.
void
consumer(void)
{
// Do something
msg_t msg;
for (; some_condition();)
{
mq.receive(&msg);
// Process message
if (msg.id == 7)
{
// Something special
}
}
// Do something else.
}
void
producer(void)
{
// Do something
msg_t msg;
msg.id = 7;
mq.send(&msg);
// Do something else.
}
Template of a POSIX compliant message queue with message type and local storage.
Definition os-mqueue.h:1047
result_t send(const value_type *msg, priority_t mprio=default_priority)
Send a typed message to the queue.
Definition os-mqueue.h:1815
result_t receive(value_type *msg, priority_t *mprio=nullptr)
Receive a typed message from the queue.
Definition os-mqueue.h:1864

Definition at line 1046 of file os-mqueue.h.

Member Typedef Documentation

◆ value_type

template<typename T , std::size_t N>
using os::rtos::message_queue_inclusive< T, N >::value_type = T

Local type of message.

Definition at line 1053 of file os-mqueue.h.

Constructor & Destructor Documentation

◆ message_queue_inclusive() [1/2]

template<typename T , std::size_t N>
os::rtos::message_queue_inclusive< T, N >::message_queue_inclusive ( const attributes attr = initializer)
inline

Construct a typed message queue object instance.

Parameters
[in]attrReference to attributes.

This constructor shall initialise a message queue object with attributes referenced by attr. If the attributes specified by attr are modified later, the memory pool attributes shall not be affected. Upon successful initialisation, the state of the message queue object shall become initialised.

Only the message queue itself may be used for performing synchronisation. It is not allowed to make copies of message queue objects.

In cases where default message queue attributes are appropriate, the variable message_queue::initializer can be used to initialise message queue. The effect shall be equivalent to creating a message queue object with the simple constructor.

The storage shall be statically allocated inside the message queue object instance.

Passing a storage via the attributes is not allowed and might trigger an assert.

Note
These objects are better instantiated as global static objects. When instantiated on the thread stack, the stack should be sized accordingly, including the internal lists overhead.

Implemented as a wrapper over the parent constructor, automatically passing the message size and the storage details.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 1736 of file os-mqueue.h.

◆ message_queue_inclusive() [2/2]

template<typename T , std::size_t N>
os::rtos::message_queue_inclusive< T, N >::message_queue_inclusive ( const char *  name,
const attributes attr = initializer 
)

Construct a named typed message queue object instance.

Parameters
[in]namePointer to name.
[in]attrReference to attributes.

This constructor shall initialise a named message queue object with attributes referenced by attr. If the attributes specified by attr are modified later, the memory pool attributes shall not be affected. Upon successful initialisation, the state of the message queue object shall become initialised.

Only the message queue itself may be used for performing synchronisation. It is not allowed to make copies of message queue objects.

In cases where default message queue attributes are appropriate, the variable message_queue::initializer can be used to initialise message queue. The effect shall be equivalent to creating a message queue object with the simple constructor.

The storage shall be statically allocated inside the message queue object instance.

Passing a storage via the attributes is not allowed and might trigger an assert.

Note
These objects are better instantiated as global static objects. When instantiated on the thread stack, the stack should be sized accordingly, including the internal lists overhead.

Implemented as a wrapper over the parent constructor, automatically passing the message size and the storage details.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 1778 of file os-mqueue.h.

◆ ~message_queue_inclusive()

template<typename T , std::size_t N>
os::rtos::message_queue_inclusive< T, N >::~message_queue_inclusive
overridevirtual

Destruct the typed message queue object instance.

This destructor shall destroy the message queue object; the object becomes, in effect, uninitialised. An implementation may cause the destructor to set the object to an invalid value.

It shall be safe to destroy an initialised message queue object upon which no threads are currently blocked. Attempting to destroy a message queue object upon which other threads are currently blocked results in undefined behaviour.

Implemented as a wrapper over the parent destructor.

Definition at line 1802 of file os-mqueue.h.

Member Function Documentation

◆ capacity()

std::size_t os::rtos::message_queue::capacity ( void  ) const
inlineinherited

Get queue capacity.

Parameters
None.
Returns
The max number of messages that can be queued.
POSIX compatibility
Note
Can be invoked from Interrupt Service Routines. Extension to standard, no POSIX similar functionality identified.

Definition at line 1312 of file os-mqueue.h.

◆ compute_allocated_size_bytes()

template<typename T >
constexpr std::size_t os::rtos::message_queue::compute_allocated_size_bytes ( std::size_t  msgs,
std::size_t  msg_size_bytes 
)
inlineconstexprinherited

Calculator for queue storage requirements.

Parameters
msgsNumber of messages.
msg_size_bytesSize of message.
Returns
Total required storage in bytes, including internal alignment.

Definition at line 250 of file os-mqueue.h.

◆ empty()

bool os::rtos::message_queue::empty ( void  ) const
inlineinherited

Check if the queue is empty.

Parameters
None.
Return values
trueThe queue has no messages.
falseThe queue has some messages.
POSIX compatibility
Extension to standard, no POSIX similar functionality identified.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 1336 of file os-mqueue.h.

◆ full()

bool os::rtos::message_queue::full ( void  ) const
inlineinherited

Check if the queue is full.

Parameters
None.
Return values
trueThe queue is full.
falseThe queue is not full.
POSIX compatibility
Extension to standard, no POSIX similar functionality identified.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 1348 of file os-mqueue.h.

◆ length()

std::size_t os::rtos::message_queue::length ( void  ) const
inlineinherited

Get queue length.

Parameters
None.
Returns
The number of messages in the queue.
POSIX compatibility
Extension to standard, no POSIX similar functionality identified.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 1300 of file os-mqueue.h.

◆ msg_size()

std::size_t os::rtos::message_queue::msg_size ( void  ) const
inlineinherited

Get message size.

Parameters
None.
Returns
The message size, in bytes.
POSIX compatibility
Extension to standard, no POSIX similar functionality identified.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 1324 of file os-mqueue.h.

◆ name()

const char * os::rtos::internal::object_named::name ( void  ) const
inlineinherited

Get object name.

Parameters
None.
Returns
A null terminated string.

All objects return a non-null string; anonymous objects return "-".

Note
Can be invoked from Interrupt Service Routines.

Definition at line 759 of file os-decls.h.

◆ operator delete()

void os::rtos::internal::object_named_system::operator delete ( void *  ptr,
std::size_t  bytes 
)
inlinestaticinherited

Deallocate the dynamically allocated object instance. using the RTOS system allocator.

Parameters
ptrPointer to object.
bytesNumber of bytes to deallocate.
Returns
Nothing.

The deallocation function (3.7.4.2) called by a delete-expression to render the value of ptr invalid.

ptr shall be a null pointer or its value shall be a value returned by an earlier call to the (possibly replaced) operator new() which has not been invalidated by an intervening call to operator delete(void*).

If ptr is null, does nothing. Otherwise, reclaims the storage allocated by the earlier call to operator new.

The storage is deallocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 122 of file os-inlines.h.

◆ operator delete[]()

void os::rtos::internal::object_named_system::operator delete[] ( void *  ptr,
std::size_t  bytes 
)
inlinestaticinherited

Deallocate the dynamically allocated array of object. instances using the RTOS system allocator.

Parameters
ptrPointer to array of objects.
bytesNumber of bytes to deallocate.
Returns
Nothing.

The deallocation function (3.7.4.2) called by the array form of a delete-expression to render the value of ptr invalid.

If ptr is null, does nothing. Otherwise, reclaims the storage allocated by the earlier call to operator new.

The storage is deallocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 143 of file os-inlines.h.

◆ operator new() [1/2]

void * os::rtos::internal::object_named_system::operator new ( std::size_t  bytes)
inlinestaticinherited

Allocate space for a new object instance using the RTOS system allocator.

Parameters
bytesNumber of bytes to allocate.
Returns
Pointer to allocated object.

The allocation function (3.7.4.1) called by a new-expression (5.3.4) to allocate a storage of size bytes suitably aligned to represent any object of that size. Return a non-null pointer to suitably aligned storage (3.7.4).

The storage is allocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 44 of file os-inlines.h.

◆ operator new() [2/2]

void * os::rtos::internal::object_named_system::operator new ( std::size_t  bytes,
void *  ptr 
)
inlinestaticinherited

Emplace a new object instance.

Parameters
bytesNumber of bytes to emplace.
ptrPointer to location to emplace the object.
Returns
Pointer to emplaced object.

The allocation function (3.7.4.1) called by a placement new-expression to allocate a storage of size bytes suitably aligned to represent any object of that size. Return a non-null pointer to suitably aligned storage (3.7.4).

The storage is allocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 81 of file os-inlines.h.

◆ operator new[]() [1/2]

void * os::rtos::internal::object_named_system::operator new[] ( std::size_t  bytes)
inlinestaticinherited

Allocate space for an array of new object instances using the RTOS system allocator.

Parameters
bytesNumber of bytes to allocate.
Returns
Pointer to allocated array.

The allocation function (3.7.4.1) called by the array form of a new-expression (5.3.4) to allocate a storage of size bytes suitably aligned to represent any array object of that size or smaller.

The storage is allocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 62 of file os-inlines.h.

◆ operator new[]() [2/2]

void * os::rtos::internal::object_named_system::operator new[] ( std::size_t  bytes,
void *  ptr 
)
inlinestaticinherited

Emplace an array of new object instances.

Parameters
bytesNumber of bytes to emplace.
ptrPointer to location to emplace the object.
Returns
Pointer to emplaced array.

The allocation function (3.7.4.1) called by the array form of a placement new-expression to allocate a storage of size bytes suitably aligned to represent any array object of that size or smaller.

The storage is allocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 98 of file os-inlines.h.

◆ operator==()

bool os::rtos::message_queue::operator== ( const message_queue rhs) const
inlineinherited

Compare memory queues.

Return values
trueThe given memory queue is the same as this memory queue.
falseThe memory queues are different.

Identical message queues should have the same memory address.

POSIX compatibility
Extension to standard, no POSIX similar functionality identified.

Definition at line 1288 of file os-mqueue.h.

◆ receive() [1/2]

template<typename T , std::size_t N>
result_t os::rtos::message_queue_inclusive< T, N >::receive ( value_type msg,
priority_t mprio = nullptr 
)
inline

Receive a typed message from the queue.

Parameters
[out]msgThe address where to store the dequeued message.
[out]mprioThe address where to store the message priority. The default is nullptr.
Return values
result::okThe message was received.
EINVALA parameter is invalid or outside of a permitted range.
EMSGSIZEThe specified message length, nbytes, is greater than the message size attribute of the message queue.
EPERMCannot be invoked from an Interrupt Service Routines.
ENOTRECOVERABLEThe message could not be dequeued (extension to POSIX).
EBADMSGThe implementation has detected a data corruption problem with the message.
EINTRThe operation was interrupted.

Wrapper over the parent method, automatically passing the message size.

See also
message_queue::receive().

Definition at line 1864 of file os-mqueue.h.

◆ receive() [2/2]

result_t os::rtos::message_queue::receive ( void *  msg,
std::size_t  nbytes,
priority_t mprio = nullptr 
)
inherited

Receive a message from the queue.

Parameters
[out]msgThe address where to store the dequeued message.
[in]nbytesThe size of the destination buffer. Must be lower than the value used when creating the queue.
[out]mprioThe address where to store the message priority. The default is nullptr.
Return values
result::okThe message was received.
EINVALA parameter is invalid or outside of a permitted range.
EMSGSIZEThe specified message length, nbytes, is greater than the message size attribute of the message queue.
EPERMCannot be invoked from an Interrupt Service Routines.
ENOTRECOVERABLEThe message could not be dequeued (extension to POSIX).
EBADMSGThe implementation has detected a data corruption problem with the message.
EINTRThe operation was interrupted.

The receive() function shall receive the oldest of the highest priority message(s) from the message queue. If the size of the buffer in bytes, specified by the nbytes argument, is less than the msg_size_bytes attribute of the message queue, the function shall fail and return an error. Otherwise, the selected message shall be removed from the queue and copied to the buffer pointed to by the msg argument.

If the value of nbytes is greater than message_queue::max_size, the result is implementation-defined.

If the argument mprio is not nullptr, the priority of the selected message shall be stored in the location referenced by mprio.

If the message queue is empty, receive() shall block until a message is enqueued on the message queue or until receive() is cancelled/interrupted. If more than one thread is waiting to receive a message when a message arrives at an empty queue and the Priority Scheduling option is supported, then the thread of highest priority that has been waiting the longest shall be selected to receive the message. Otherwise, it is unspecified which waiting thread receives the message.

POSIX compatibility
Inspired by mq_receive() with O_NONBLOCK not set, from <mqueue.h> (IEEE Std 1003.1, 2013 Edition).
Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 1211 of file os-mqueue.cpp.

◆ reset()

result_t os::rtos::message_queue::reset ( void  )
inherited

Reset the message queue.

Parameters
None.
Return values
result::okThe queue was reset.
EPERMCannot be invoked from an Interrupt Service Routines.

Clear both send and receive counter and return the queue to the initial state.

POSIX compatibility
Extension to standard, no POSIX similar functionality identified.
Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 1534 of file os-mqueue.cpp.

◆ send() [1/2]

template<typename T , std::size_t N>
result_t os::rtos::message_queue_inclusive< T, N >::send ( const value_type msg,
priority_t  mprio = default_priority 
)
inline

Send a typed message to the queue.

Parameters
[in]msgThe address of the message to enqueue.
[in]mprioThe message priority. The default is 0.
Return values
result::okThe message was enqueued.
EINVALA parameter is invalid or outside of a permitted range.
EMSGSIZEThe specified message length, nbytes, exceeds the message size attribute of the message queue.
EPERMCannot be invoked from an Interrupt Service Routines.
ENOTRECOVERABLEThe message could not be enqueue (extension to POSIX).
EINTRThe operation was interrupted.

Wrapper over the parent method, automatically passing the message size.

See also
message_queue::send().

Definition at line 1815 of file os-mqueue.h.

◆ send() [2/2]

result_t os::rtos::message_queue::send ( const void *  msg,
std::size_t  nbytes,
priority_t  mprio = default_priority 
)
inherited

Send a message to the queue.

Parameters
[in]msgThe address of the message to enqueue.
[in]nbytesThe length of the message. Must be not higher than the value used when creating the queue.
[in]mprioThe message priority. The default is 0.
Return values
result::okThe message was enqueued.
EINVALA parameter is invalid or outside of a permitted range.
EMSGSIZEThe specified message length, nbytes, exceeds the message size attribute of the message queue.
EPERMCannot be invoked from an Interrupt Service Routines.
ENOTRECOVERABLEThe message could not be enqueue (extension to POSIX).
EINTRThe operation was interrupted.

The send() function shall add the message pointed to by the argument msg to the message queue. The nbytes argument specifies the length of the message, in bytes, pointed to by msg. The value of nbytes shall be less than or equal to the msg_size_bytes parameter of the message queue object, or send() shall fail.

If the specified message queue is not full, send() shall behave as if the message is inserted into the message queue at the position indicated by the mprio argument. A message with a larger numeric value of mprio shall be inserted before messages with lower values of mprio. A message shall be inserted after other messages in the queue, if any, with equal mprio. The value of mprio shall be less than message_queue::max_priority.

If the specified message queue is full, send() shall block until space becomes available to enqueue the message, or until send() is cancelled/interrupted. If more than one thread is waiting to send when space becomes available in the message queue and the Priority Scheduling option is supported, then the thread of the highest priority that has been waiting the longest shall be unblocked to send its message. Otherwise, it is unspecified which waiting thread is unblocked.

POSIX compatibility
Inspired by mq_send() with O_NONBLOCK not set, from <mqueue.h> (IEEE Std 1003.1, 2013 Edition).
Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 879 of file os-mqueue.cpp.

◆ timed_receive() [1/2]

template<typename T , std::size_t N>
result_t os::rtos::message_queue_inclusive< T, N >::timed_receive ( value_type msg,
clock::duration_t  timeout,
priority_t mprio = nullptr 
)
inline

Receive a typed message from the queue with timeout.

Parameters
[out]msgThe address where to store the dequeued message.
[in]timeoutThe timeout duration.
[out]mprioThe address where to store the message priority. The default is nullptr.
Return values
result::okThe message was received.
EINVALA parameter is invalid or outside of a permitted range.
EMSGSIZEThe specified message length, nbytes, is greater than the message size attribute of the message queue.
EPERMCannot be invoked from an Interrupt Service Routines.
ENOTRECOVERABLEThe message could not be dequeued (extension to POSIX).
EBADMSGThe implementation has detected a data corruption problem with the message.
EINTRThe operation was interrupted.
ETIMEDOUTNo message arrived on the queue before the specified timeout expired.

Wrapper over the parent method, automatically passing the message size.

See also
message_queue::timed_receive().

Definition at line 1896 of file os-mqueue.h.

◆ timed_receive() [2/2]

result_t os::rtos::message_queue::timed_receive ( void *  msg,
std::size_t  nbytes,
clock::duration_t  timeout,
priority_t mprio = nullptr 
)
inherited

Receive a message from the queue with timeout.

Parameters
[out]msgThe address where to store the dequeued message.
[in]nbytesThe size of the destination buffer. Must be lower than the value used when creating the queue.
[in]timeoutThe timeout duration.
[out]mprioThe address where to store the message priority. The default is nullptr.
Return values
result::okThe message was received.
EINVALA parameter is invalid or outside of a permitted range.
EMSGSIZEThe specified message length, nbytes, is greater than the message size attribute of the message queue.
EPERMCannot be invoked from an Interrupt Service Routines.
ENOTRECOVERABLEThe message could not be dequeued (extension to POSIX).
EBADMSGThe implementation has detected a data corruption problem with the message.
EINTRThe operation was interrupted.
ETIMEDOUTNo message arrived on the queue before the specified timeout expired.

The timed_receive() function shall receive the oldest of the highest priority message(s) from the message queue. If the size of the buffer in bytes, specified by the nbytes argument, is less than the msg_size_bytes attribute of the message queue, the function shall fail and return an error. Otherwise, the selected message shall be removed from the queue and copied to the buffer pointed to by the msg argument.

If the value of nbytes is greater than message_queue::max_size, the result is implementation-defined.

If the argument mprio is not nullptr, the priority of the selected message shall be stored in the location referenced by mprio.

If the message queue is empty, timed_receive() shall block until a message is enqueued on the message queue or until timed_receive() is cancelled/interrupted. If more than one thread is waiting to receive a message when a message arrives at an empty queue and the Priority Scheduling option is supported, then the thread of highest priority that has been waiting the longest shall be selected to receive the message. Otherwise, it is unspecified which waiting thread receives the message.

The timed_receive() function shall receive the oldest of the highest priority messages from the message queue as described for the receive() function. However, if no message exists on the queue to satisfy the receive, the wait for such a message shall be terminated when the specified timeout expires.

The timeout shall expire after the number of time units (that is when the value of that clock equals or exceeds (now()+duration). The resolution of the timeout shall be the resolution of the clock on which it is based.

Under no circumstance shall the operation fail with a timeout if a message can be removed from the message queue immediately.

The clock used for timeouts can be specified via the clock attribute. By default, the clock derived from the scheduler timer is used, and the durations are expressed in ticks.

Compatible with POSIX mq_receive() with O_NONBLOCK set. http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html#

POSIX compatibility
Inspired by mq_timedreceive() with O_NONBLOCK not set, from <mqueue.h> (IEEE Std 1003.1, 2013 Edition).
Differences from the standard:
  • the timeout is not expressed as an absolute time point, but as a relative number of timer ticks (by default, the SysTick clock for CMSIS).
Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 1421 of file os-mqueue.cpp.

◆ timed_send() [1/2]

template<typename T , std::size_t N>
result_t os::rtos::message_queue_inclusive< T, N >::timed_send ( const value_type msg,
clock::duration_t  timeout,
priority_t  mprio = default_priority 
)
inline

Send a typed message to the queue with timeout.

Parameters
[in]msgThe address of the message to enqueue.
[in]timeoutThe timeout duration.
[in]mprioThe message priority. The default is 0.
Return values
result::okThe message was enqueued.
EINVALA parameter is invalid or outside of a permitted range.
EMSGSIZEThe specified message length, nbytes, exceeds the message size attribute of the message queue.
EPERMCannot be invoked from an Interrupt Service Routines.
ETIMEDOUTThe timeout expired before the message could be added to the queue.
ENOTRECOVERABLEThe message could not be enqueue (extension to POSIX).
EINTRThe operation was interrupted.

Wrapper over the parent method, automatically passing the message size.

See also
message_queue::timed_send().

Definition at line 1847 of file os-mqueue.h.

◆ timed_send() [2/2]

result_t os::rtos::message_queue::timed_send ( const void *  msg,
std::size_t  nbytes,
clock::duration_t  timeout,
priority_t  mprio = default_priority 
)
inherited

Send a message to the queue with timeout.

Parameters
[in]msgThe address of the message to enqueue.
[in]nbytesThe length of the message. Must be not higher than the value used when creating the queue.
[in]timeoutThe timeout duration.
[in]mprioThe message priority. The default is 0.
Return values
result::okThe message was enqueued.
EINVALA parameter is invalid or outside of a permitted range.
EMSGSIZEThe specified message length, nbytes, exceeds the message size attribute of the message queue.
EPERMCannot be invoked from an Interrupt Service Routines.
ETIMEDOUTThe timeout expired before the message could be added to the queue.
ENOTRECOVERABLEThe message could not be enqueue (extension to POSIX).
EINTRThe operation was interrupted.

The timed_send() function shall add the message pointed to by the argument msg to the message queue. The nbytes argument specifies the length of the message, in bytes, pointed to by msg. The value of nbytes shall be less than or equal to the msg_size_bytes attribute of the message queue object, or timed_send() shall fail.

If the message queue is not full, timed_send() shall behave as if the message is inserted into the message queue at the position indicated by the mprio argument. A message with a larger numeric value of mprio shall be inserted before messages with lower values of mprio. A message shall be inserted after other messages in the queue, if any, with equal mprio. The value of mprio shall be less than message_queue::max_priority.

If the message queue is full, the wait for sufficient room in the queue shall be terminated when the specified timeout expires.

The timeout shall expire after the number of time units (that is when the value of that clock equals or exceeds (now()+timeout). The resolution of the timeout shall be the resolution of the clock on which it is based.

Under no circumstance shall the operation fail with a timeout if there is sufficient room in the queue to add the message immediately.

The clock used for timeouts can be specified via the clock attribute. By default, the clock derived from the scheduler timer is used, and the durations are expressed in ticks.

POSIX compatibility
Inspired by mq_timedsend() with O_NONBLOCK not set, from <mqueue.h> (IEEE Std 1003.1, 2013 Edition).
Differences from the standard:
  • the timeout is not expressed as an absolute time point, but as a relative number of timer ticks (by default, the SysTick clock for CMSIS).
Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 1074 of file os-mqueue.cpp.

◆ try_receive() [1/2]

template<typename T , std::size_t N>
result_t os::rtos::message_queue_inclusive< T, N >::try_receive ( value_type msg,
priority_t mprio = nullptr 
)
inline

Try to receive a typed message from the queue.

Parameters
[out]msgThe address where to store the dequeued message. be lower than the value used when creating the queue.
[out]mprioThe address where to store the message priority. The default is nullptr.
Return values
result::okThe message was received.
EINVALA parameter is invalid or outside of a permitted range.
EMSGSIZEThe specified message length, nbytes, is greater than the message size attribute of the message queue.
ENOTRECOVERABLEThe message could not be dequeued (extension to POSIX).
EBADMSGThe implementation has detected a data corruption problem with the message.
EWOULDBLOCKThe specified message queue is empty.

Wrapper over the parent method, automatically passing the message size.

See also
message_queue::try_receive().

Definition at line 1880 of file os-mqueue.h.

◆ try_receive() [2/2]

result_t os::rtos::message_queue::try_receive ( void *  msg,
std::size_t  nbytes,
priority_t mprio = nullptr 
)
inherited

Try to receive a message from the queue.

Parameters
[out]msgThe address where to store the dequeued message.
[in]nbytesThe size of the destination buffer. Must be lower than the value used when creating the queue.
[out]mprioThe address where to store the message priority. The default is nullptr.
Return values
result::okThe message was received.
EINVALA parameter is invalid or outside of a permitted range.
EMSGSIZEThe specified message length, nbytes, is greater than the message size attribute of the message queue.
ENOTRECOVERABLEThe message could not be dequeued (extension to POSIX).
EBADMSGThe implementation has detected a data corruption problem with the message.
EWOULDBLOCKThe specified message queue is empty.

The try_receive() function shall try to receive the oldest of the highest priority message(s) from the message queue. If the size of the buffer in bytes, specified by the nbytes argument, is less than the msg_size_bytes attribute of the message queue, the function shall fail and return an error. Otherwise, the selected message shall be removed from the queue and copied to the buffer pointed to by the msg argument.

If the value of nbytes is greater than message_queue::max_size, the result is implementation-defined.

If the argument mprio is not nullptr, the priority of the selected message shall be stored in the location referenced by mprio.

If the message queue is empty, no message shall be removed from the queue, and try_receive() shall return an error.

POSIX compatibility
Inspired by mq_receive() with O_NONBLOCK set, from <mqueue.h> (IEEE Std 1003.1, 2013 Edition).
Differences from the standard:
  • for consistency reasons, EWOULDBLOCK is used, instead of EAGAIN
Note
Can be invoked from Interrupt Service Routines.

Definition at line 1323 of file os-mqueue.cpp.

◆ try_send() [1/2]

template<typename T , std::size_t N>
result_t os::rtos::message_queue_inclusive< T, N >::try_send ( const value_type msg,
priority_t  mprio = default_priority 
)
inline

Try to send a typed message to the queue.

Parameters
[in]msgThe address of the message to enqueue. higher than the value used when creating the queue.
[in]mprioThe message priority. The default is 0.
Return values
result::okThe message was enqueued.
EWOULDBLOCKThe specified message queue is full.
EINVALA parameter is invalid or outside of a permitted range.
EMSGSIZEThe specified message length, nbytes, exceeds the message size attribute of the message queue.
ENOTRECOVERABLEThe message could not be enqueue (extension to POSIX).

Wrapper over the parent method, automatically passing the message size.

See also
message_queue::try_send().

Definition at line 1831 of file os-mqueue.h.

◆ try_send() [2/2]

result_t os::rtos::message_queue::try_send ( const void *  msg,
std::size_t  nbytes,
priority_t  mprio = default_priority 
)
inherited

Try to send a message to the queue.

Parameters
[in]msgThe address of the message to enqueue.
[in]nbytesThe length of the message. Must be not higher than the value used when creating the queue.
[in]mprioThe message priority. The default is 0.
Return values
result::okThe message was enqueued.
EWOULDBLOCKThe specified message queue is full.
EINVALA parameter is invalid or outside of a permitted range.
EMSGSIZEThe specified message length, nbytes, exceeds the message size attribute of the message queue.
ENOTRECOVERABLEThe message could not be enqueue (extension to POSIX).

The try_send() function shall try to add the message pointed to by the argument msg to the message queue. The nbytes argument specifies the length of the message, in bytes, pointed to by msg. The value of nbytes shall be less than or equal to the msg_size_bytes parameter of the message queue object, or try_send() shall fail.

If the message queue is not full, try_send() shall behave as if the message is inserted into the message queue at the position indicated by the mprio argument. A message with a larger numeric value of mprio shall be inserted before messages with lower values of mprio. A message shall be inserted after other messages in the queue, if any, with equal mprio. The value of mprio shall be less than message_queue::max_priority.

If the message queue is full, the message shall not be queued and try_send() shall return an error.

POSIX compatibility
Inspired by mq_send() with O_NONBLOCK set, from <mqueue.h> (IEEE Std 1003.1, 2013 Edition).
Differences from the standard:
  • for consistency reasons, EWOULDBLOCK is used, instead of EAGAIN
Note
Can be invoked from Interrupt Service Routines.

Definition at line 990 of file os-mqueue.cpp.

Member Data Documentation

◆ msgs

template<typename T , std::size_t N>
const std::size_t os::rtos::message_queue_inclusive< T, N >::msgs = N
static

Local constant based on template definition.

Definition at line 1058 of file os-mqueue.h.


The documentation for this class was generated from the following file: