µ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-mqueue.h
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2016-2025 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can
9 * be obtained from https://opensource.org/licenses/mit.
10 */
11
12#ifndef CMSIS_PLUS_RTOS_OS_MQUEUE_H_
13#define CMSIS_PLUS_RTOS_OS_MQUEUE_H_
14
15// ----------------------------------------------------------------------------
16
17#if defined(__cplusplus)
18
19// ----------------------------------------------------------------------------
20
21#if defined(OS_USE_OS_APP_CONFIG_H)
22#include <cmsis-plus/os-app-config.h>
23#endif
24
27
29
30// ----------------------------------------------------------------------------
31
32#pragma GCC diagnostic push
33#if defined(__clang__)
34#pragma clang diagnostic ignored "-Wc++98-compat"
35#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
36#endif
37
38// ----------------------------------------------------------------------------
39
40namespace os
41{
42 namespace rtos
43 {
44
45 // ========================================================================
46
47#pragma GCC diagnostic push
48#if defined(__clang__)
49#pragma clang diagnostic ignored "-Wpadded"
50#elif defined(__GNUC__)
51#pragma GCC diagnostic ignored "-Wpadded"
52#endif
53
60#pragma GCC diagnostic push
61#if defined(__clang__)
62#elif defined(__GNUC__)
63#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
64#pragma GCC diagnostic ignored "-Wsuggest-final-types"
65#endif
67 {
68 public:
69 // ======================================================================
70
80#if defined(OS_BOOL_RTOS_MESSAGE_QUEUE_SIZE_16BITS)
81 using size_t = uint16_t;
82#else
83 using size_t = uint8_t;
84#endif
85
90 static constexpr message_queue::size_t max_size = 0xFF;
91
96 using msg_size_t = uint16_t;
97
102 static constexpr msg_size_t max_msg_size = 0xFFFF;
103
109
114 static constexpr index_t no_index = max_size;
115
125 using priority_t = uint8_t;
126
134 static constexpr priority_t default_priority = 0;
135
144 static constexpr priority_t max_priority = 0xFF;
145
146 // ======================================================================
147
154 {
155 public:
166 constexpr attributes ();
167
168 // The rule of five.
169 attributes (const attributes&) = default;
170 attributes (attributes&&) = default;
173 = default;
176 = default;
177
181 ~attributes () = default;
182
187 public:
193 // Public members; no accessors and mutators required.
194 // Warning: must match the type & order of the C file header.
198 void* mq_queue_address = nullptr;
199
203 std::size_t mq_queue_size_bytes = 0;
204
205 // Add more attributes here.
206
211 }; /* class attributes */
212
218
225
235 template <typename T, std::size_t msgs, std::size_t msg_size_bytes>
236 class arena
237 {
238 public:
239 T queue[(msgs * msg_size_bytes + sizeof (T) - 1) / sizeof (T)];
240 T links[((2 * msgs) * sizeof (index_t) + sizeof (T) - 1) / sizeof (T)];
241 T prios[(msgs * sizeof (priority_t) + sizeof (T) - 1) / sizeof (T)];
242 };
243
251 template <typename T>
252 constexpr std::size_t
254 std::size_t msg_size_bytes)
255 {
256 // Align each message
257 return (msgs
258 * ((msg_size_bytes + (sizeof (T) - 1)) & ~(sizeof (T) - 1)))
259 // Align the indices array
260 + ((2 * msgs * sizeof (index_t) + (sizeof (T) - 1))
261 & ~(sizeof (T) - 1))
262 // Align the priority array
263 + ((msgs * sizeof (priority_t) + (sizeof (T) - 1))
264 & ~(sizeof (T) - 1));
265 }
266
267 // ======================================================================
268
282 message_queue (std::size_t msgs, std::size_t msg_size_bytes,
283 const attributes& attr = initializer,
284 const allocator_type& allocator = allocator_type ());
285
295 message_queue (const char* name, std::size_t msgs,
296 std::size_t msg_size_bytes,
297 const attributes& attr = initializer,
298 const allocator_type& allocator = allocator_type ());
299
300 protected:
305 // Internal constructors, used from templates.
306 message_queue ();
307 message_queue (const char* name);
308
313 public:
318 // The rule of five.
319 message_queue (const message_queue&) = delete;
320 message_queue (message_queue&&) = delete;
322 operator= (const message_queue&)
323 = delete;
325 operator= (message_queue&&)
326 = delete;
327
335 virtual ~message_queue ();
336
351 bool
352 operator== (const message_queue& rhs) const;
353
358 public:
380 send (const void* msg, std::size_t nbytes,
382
398 try_send (const void* msg, std::size_t nbytes,
400
420 timed_send (const void* msg, std::size_t nbytes,
421 clock::duration_t timeout,
423
443 receive (void* msg, std::size_t nbytes, priority_t* mprio = nullptr);
444
463 try_receive (void* msg, std::size_t nbytes, priority_t* mprio = nullptr);
464
487 timed_receive (void* msg, std::size_t nbytes, clock::duration_t timeout,
488 priority_t* mprio = nullptr);
489
490 // TODO: check if some kind of peek() is useful.
491
498 std::size_t
499 capacity (void) const;
500
507 std::size_t
508 length (void) const;
509
516 std::size_t
517 msg_size (void) const;
518
526 bool
527 empty (void) const;
528
536 bool
537 full (void) const;
538
547 reset (void);
548
553 protected:
573 void
574 internal_construct_ (std::size_t msgs, std::size_t msg_size_bytes,
575 const attributes& attr, void* queue_address,
576 std::size_t queue_size_bytes);
577
585 void
586 internal_init_ (void);
587
588#if !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE)
589
599 bool
600 internal_try_send_ (const void* msg, std::size_t nbytes,
601 priority_t mprio);
602
613 bool
614 internal_try_receive_ (void* msg, std::size_t nbytes, priority_t* mprio);
615
616#endif /* !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE) */
617
626 protected:
636 // Keep these in sync with the structure declarations in os-c-decl.h.
637#if !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE)
645 internal::waiting_threads_list receive_list_;
649 clock* clock_ = nullptr;
650
651 // To save space, the double linked list is built
652 // using short indexes, not pointers.
656 volatile index_t* prev_array_ = nullptr;
660 volatile index_t* next_array_ = nullptr;
664 volatile priority_t* prio_array_ = nullptr;
665
676 void* volatile first_free_ = nullptr;
677#endif /* !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE) */
678
683 void* queue_addr_ = nullptr;
688 void* allocated_queue_addr_ = nullptr;
692 const void* allocator_ = nullptr;
693
694#if defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE)
695 friend class port::message_queue;
696 os_mqueue_port_data_t port_;
697#endif
698
703 std::size_t queue_size_bytes_ = 0;
707 std::size_t allocated_queue_size_elements_ = 0;
708
712 message_queue::msg_size_t msg_size_bytes_ = 0;
716 message_queue::size_t msgs_ = 0;
720 message_queue::size_t count_ = 0;
721
722#if !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE)
726 index_t head_ = 0;
727#endif /* !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE) */
728
736 };
737#pragma GCC diagnostic pop
738
739 // ========================================================================
740
746 template <typename Allocator = memory::allocator<void*>>
748 {
749 public:
753 using allocator_type = Allocator;
754
768 message_queue_allocated (std::size_t msgs, std::size_t msg_size_bytes,
769 const attributes& attr = initializer,
770 const allocator_type& allocator
771 = allocator_type ());
772
782 message_queue_allocated (const char* name, std::size_t msgs,
783 std::size_t msg_size_bytes,
784 const attributes& attr = initializer,
785 const allocator_type& allocator
786 = allocator_type ());
787
788 public:
793 // The rule of five.
797 operator= (const message_queue_allocated&)
798 = delete;
800 operator= (message_queue_allocated&&)
801 = delete;
802
810 virtual ~message_queue_allocated () override;
811
815 };
816
817 // ========================================================================
818
825#pragma GCC diagnostic push
826#if defined(__clang__)
827#elif defined(__GNUC__)
828#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
829#pragma GCC diagnostic ignored "-Wsuggest-final-types"
830#endif
831 template <typename T, typename Allocator = memory::allocator<void*>>
833 {
834 public:
838 using value_type = T;
839
843 using allocator_type = Allocator;
844
857 message_queue_typed (std::size_t msgs,
858 const message_queue::attributes& attr
860 const allocator_type& allocator
861 = allocator_type ());
862
871 message_queue_typed (const char* name, std::size_t msgs,
872 const message_queue::attributes& attr
874 const allocator_type& allocator
875 = allocator_type ());
876
881 // The rule of five.
885 operator= (const message_queue_typed&)
886 = delete;
888 operator= (message_queue_typed&&)
889 = delete;
890
898 virtual ~message_queue_typed () override;
899
904 public:
924 send (const value_type* msg,
926
943
961 timed_send (const value_type* msg, clock::duration_t timeout,
964
982 receive (value_type* msg, message_queue::priority_t* mprio = nullptr);
983
1000 result_t
1001 try_receive (value_type* msg,
1002 message_queue::priority_t* mprio = nullptr);
1003
1023 result_t
1025 message_queue::priority_t* mprio = nullptr);
1026
1030 };
1031#pragma GCC diagnostic pop
1032
1033 // ========================================================================
1034
1041 template <typename T, std::size_t N>
1043 {
1044 public:
1048 using value_type = T;
1049
1053 static const std::size_t msgs = N;
1054
1065
1071 message_queue_inclusive (const char* name,
1072 const attributes& attr = initializer);
1073
1078 // The rule of five.
1082 operator= (const message_queue_inclusive&)
1083 = delete;
1085 operator= (message_queue_inclusive&&)
1086 = delete;
1087
1095 virtual ~message_queue_inclusive () override;
1096
1101 public:
1120 result_t
1121 send (const value_type* msg, priority_t mprio = default_priority);
1122
1136 result_t
1137 try_send (const value_type* msg, priority_t mprio = default_priority);
1138
1155 result_t
1156 timed_send (const value_type* msg, clock::duration_t timeout,
1158
1175 result_t
1176 receive (value_type* msg, priority_t* mprio = nullptr);
1177
1194 result_t
1195 try_receive (value_type* msg, priority_t* mprio = nullptr);
1196
1216 result_t
1218 priority_t* mprio = nullptr);
1219
1224 protected:
1244 arena<void*, msgs, sizeof (value_type)> arena_;
1245
1253 };
1254
1255#pragma GCC diagnostic pop
1256
1257 } // namespace rtos
1258 /* namespace rtos */
1259} /* namespace os */
1260
1261// ===== Inline & template implementations ====================================
1262
1263namespace os
1264{
1265 namespace rtos
1266 {
1268 {
1269 }
1270
1271 // ========================================================================
1272
1280 inline bool
1282 {
1283 return this == &rhs;
1284 }
1285
1292 inline std::size_t
1294 {
1295 return count_;
1296 }
1297
1304 inline std::size_t
1306 {
1307 return msgs_;
1308 }
1309
1316 inline std::size_t
1318 {
1319 return msg_size_bytes_;
1320 }
1321
1328 inline bool
1330 {
1331 return (length () == 0);
1332 }
1333
1340 inline bool
1342 {
1343 return (length () == capacity ());
1344 }
1345
1346 // ========================================================================
1347
1374 template <typename Allocator>
1376 std::size_t msgs, std::size_t msg_size_bytes, const attributes& attr,
1377 const allocator_type& allocator)
1378 : message_queue_allocated{ nullptr, msgs, msg_size_bytes, attr,
1379 allocator }
1380 {
1381 }
1382
1409 template <typename Allocator>
1411 const char* name, std::size_t msgs, std::size_t msg_size_bytes,
1412 const attributes& attr, const allocator_type& allocator)
1413 : message_queue{ name }
1414 {
1415#if defined(OS_TRACE_RTOS_MQUEUE)
1416 trace::printf ("%s() @%p %s %d %d\n", __func__, this, this->name (),
1417 msgs, msg_size_bytes);
1418#endif
1419
1420 if (attr.mq_queue_address != nullptr)
1421 {
1422 // Do not use any allocator at all.
1423 internal_construct_ (msgs, msg_size_bytes, attr, nullptr, 0);
1424 }
1425 else
1426 {
1427 allocator_ = &allocator;
1428
1429 // If no user storage was provided via attributes,
1430 // allocate it dynamically via the allocator.
1431 allocated_queue_size_elements_
1433 typename allocator_type::value_type> (msgs,
1434 msg_size_bytes)
1435 + sizeof (typename allocator_type::value_type) - 1)
1436 / sizeof (typename allocator_type::value_type);
1437
1438 allocated_queue_addr_
1439 = const_cast<allocator_type&> (allocator).allocate (
1440 allocated_queue_size_elements_);
1441
1442 internal_construct_ (
1443 msgs, msg_size_bytes, attr, allocated_queue_addr_,
1444 allocated_queue_size_elements_
1445 * sizeof (typename allocator_type::value_type));
1446 }
1447 }
1448
1463 template <typename Allocator>
1465 {
1466#if defined(OS_TRACE_RTOS_MQUEUE)
1467 trace::printf ("%s() @%p %s\n", __func__, this, name ());
1468#endif
1469 typedef typename std::allocator_traits<allocator_type>::pointer pointer;
1470
1471 if (allocated_queue_addr_ != nullptr)
1472 {
1473 static_cast<allocator_type*> (const_cast<void*> (allocator_))
1474 ->deallocate (static_cast<pointer> (allocated_queue_addr_),
1475 allocated_queue_size_elements_);
1476
1477 allocated_queue_addr_ = nullptr;
1478 }
1479 }
1480
1481 // ========================================================================
1482
1512 template <typename T, typename Allocator>
1514 std::size_t msgs, const message_queue::attributes& attr,
1515 const allocator_type& allocator)
1517 attr, allocator }
1518 {
1519 }
1520
1550 template <typename T, typename Allocator>
1552 const char* name, std::size_t msgs,
1553 const message_queue::attributes& attr, const allocator_type& allocator)
1555 sizeof (value_type), attr,
1556 allocator }
1557 {
1558 }
1559
1576#pragma GCC diagnostic push
1577#if defined(__clang__)
1578#elif defined(__GNUC__)
1579#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
1580#endif
1581 template <typename T, typename Allocator>
1583 {
1584 }
1585#pragma GCC diagnostic pop
1586
1594 template <typename T, typename Allocator>
1595 inline result_t
1598 {
1600 reinterpret_cast<const char*> (msg), sizeof (value_type), mprio);
1601 }
1602
1610 template <typename T, typename Allocator>
1611 inline result_t
1613 const value_type* msg, message_queue::priority_t mprio)
1614 {
1616 reinterpret_cast<const char*> (msg), sizeof (value_type), mprio);
1617 }
1618
1626 template <typename T, typename Allocator>
1627 inline result_t
1629 const value_type* msg, clock::duration_t timeout,
1631 {
1633 reinterpret_cast<const char*> (msg), sizeof (value_type), timeout,
1634 mprio);
1635 }
1636
1644 template <typename T, typename Allocator>
1645 inline result_t
1648 {
1650 reinterpret_cast<char*> (msg), sizeof (value_type), mprio);
1651 }
1652
1660 template <typename T, typename Allocator>
1661 inline result_t
1664 {
1666 reinterpret_cast<char*> (msg), sizeof (value_type), mprio);
1667 }
1668
1676 template <typename T, typename Allocator>
1677 inline result_t
1679 value_type* msg, clock::duration_t timeout,
1681 {
1683 reinterpret_cast<char*> (msg), sizeof (value_type), timeout, mprio);
1684 }
1685
1686 // ========================================================================
1687
1722 template <typename T, std::size_t N>
1724 const attributes& attr)
1725 : message_queue_inclusive{ nullptr, attr }
1726 {
1727 }
1728
1763 template <typename T, std::size_t N>
1765 const char* name, const attributes& attr)
1766 : message_queue (name)
1767 {
1768 static_assert (sizeof (T) >= sizeof (void*),
1769 "Messages of message_queue need to have at least the "
1770 "size of a pointer");
1771
1772 internal_construct_ (msgs, sizeof (value_type), attr, &arena_,
1773 sizeof (arena_));
1774 }
1775
1789 template <typename T, std::size_t N>
1791 {
1792 }
1793
1801 template <typename T, std::size_t N>
1802 inline result_t
1804 priority_t mprio)
1805 {
1806 return message_queue::send (reinterpret_cast<const char*> (msg),
1807 sizeof (value_type), mprio);
1808 }
1809
1817 template <typename T, std::size_t N>
1818 inline result_t
1820 priority_t mprio)
1821 {
1822 return message_queue::try_send (reinterpret_cast<const char*> (msg),
1823 sizeof (value_type), mprio);
1824 }
1825
1833 template <typename T, std::size_t N>
1834 inline result_t
1836 clock::duration_t timeout,
1837 priority_t mprio)
1838 {
1839 return message_queue::timed_send (reinterpret_cast<const char*> (msg),
1840 sizeof (value_type), timeout, mprio);
1841 }
1842
1850 template <typename T, std::size_t N>
1851 inline result_t
1853 {
1854 return message_queue::receive (reinterpret_cast<char*> (msg),
1855 sizeof (value_type), mprio);
1856 }
1857
1865 template <typename T, std::size_t N>
1866 inline result_t
1868 priority_t* mprio)
1869 {
1870 return message_queue::try_receive (reinterpret_cast<char*> (msg),
1871 sizeof (value_type), mprio);
1872 }
1873
1881 template <typename T, std::size_t N>
1882 inline result_t
1884 clock::duration_t timeout,
1885 priority_t* mprio)
1886 {
1888 reinterpret_cast<char*> (msg), sizeof (value_type), timeout, mprio);
1889 }
1890
1891 } /* namespace rtos */
1892} /* namespace os */
1893
1894#pragma GCC diagnostic pop
1895
1896// ----------------------------------------------------------------------------
1897
1898#endif /* __cplusplus */
1899
1900// ----------------------------------------------------------------------------
1901
1902#endif /* CMSIS_PLUS_RTOS_OS_MQUEUE_H_ */
Generic clock.
Definition os-clocks.h:61
Base class for attributes.
Definition os-decls.h:559
Base class for named system objects.
Definition os-decls.h:443
const char * name(void) const
Get object name.
Definition os-decls.h:753
Priority ordered list of threads.
Definition os-lists.h:543
Standard allocator based on the RTOS system default memory manager.
Definition os-memory.h:538
Storage for a static message queue.
Definition os-mqueue.h:237
T prios[(msgs *sizeof(priority_t)+sizeof(T) - 1)/sizeof(T)]
Definition os-mqueue.h:241
T queue[(msgs *msg_size_bytes+sizeof(T) - 1)/sizeof(T)]
Definition os-mqueue.h:239
T links[((2 *msgs) *sizeof(index_t)+sizeof(T) - 1)/sizeof(T)]
Definition os-mqueue.h:240
Message queue attributes.
Definition os-mqueue.h:154
attributes(attributes &&)=default
attributes(const attributes &)=default
constexpr attributes()
Construct a message queue attributes object instance.
Definition os-mqueue.h:1267
void * mq_queue_address
Address of the user defined storage for the message queue.
Definition os-mqueue.h:198
std::size_t mq_queue_size_bytes
Size of the user defined storage for the message queue.
Definition os-mqueue.h:203
attributes & operator=(const attributes &)=default
~attributes()=default
Destruct the message queue attributes object instance.
Template of a POSIX compliant message queue with allocator.
Definition os-mqueue.h:748
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.
Definition os-mqueue.h:1375
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.
Definition os-mqueue.h:1410
virtual ~message_queue_allocated() override
Destruct the message queue.
Definition os-mqueue.h:1464
Allocator allocator_type
Standard allocator type definition.
Definition os-mqueue.h:753
Template of a POSIX compliant message queue with message type and local storage.
Definition os-mqueue.h:1043
T value_type
Local type of message.
Definition os-mqueue.h:1048
result_t send(const value_type *msg, priority_t mprio=default_priority)
Send a typed message to the queue.
Definition os-mqueue.h:1803
virtual ~message_queue_inclusive() override
Destruct the typed message queue object instance.
Definition os-mqueue.h:1790
result_t try_send(const value_type *msg, priority_t mprio=default_priority)
Try to send a typed message to the queue.
Definition os-mqueue.h:1819
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.
Definition os-mqueue.h:1835
message_queue_inclusive(const attributes &attr=initializer)
Construct a typed message queue object instance.
Definition os-mqueue.h:1723
static const std::size_t msgs
Local constant based on template definition.
Definition os-mqueue.h:1053
result_t receive(value_type *msg, priority_t *mprio=nullptr)
Receive a typed message from the queue.
Definition os-mqueue.h:1852
result_t timed_receive(value_type *msg, clock::duration_t timeout, priority_t *mprio=nullptr)
Receive a typed message from the queue with timeout.
Definition os-mqueue.h:1883
result_t try_receive(value_type *msg, priority_t *mprio=nullptr)
Try to receive a typed message from the queue.
Definition os-mqueue.h:1867
Template of a POSIX compliant message queue with message type and allocator.
Definition os-mqueue.h:833
T value_type
Standard allocator type definition.
Definition os-mqueue.h:838
result_t send(const value_type *msg, message_queue::priority_t mprio=message_queue::default_priority)
Send a typed message to the queue.
Definition os-mqueue.h:1596
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.
Definition os-mqueue.h:1612
Allocator allocator_type
Standard allocator type definition.
Definition os-mqueue.h:843
result_t try_receive(value_type *msg, message_queue::priority_t *mprio=nullptr)
Try to receive a typed message from the queue.
Definition os-mqueue.h:1662
result_t receive(value_type *msg, message_queue::priority_t *mprio=nullptr)
Receive a typed message from the queue.
Definition os-mqueue.h:1646
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.
Definition os-mqueue.h:1678
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.
Definition os-mqueue.h:1513
virtual ~message_queue_typed() override
Destruct the typed message queue object instance.
Definition os-mqueue.h:1582
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.
Definition os-mqueue.h:1628
POSIX compliant message queue, using the default RTOS allocator.
Definition os-mqueue.h:67
bool empty(void) const
Check if the queue is empty.
Definition os-mqueue.h:1329
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.
Definition os-mqueue.h:1305
std::size_t msg_size(void) const
Get message size.
Definition os-mqueue.h:1317
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.
Definition os-mqueue.h:253
bool full(void) const
Check if the queue is full.
Definition os-mqueue.h:1341
std::size_t length(void) const
Get queue length.
Definition os-mqueue.h:1293
bool operator==(const message_queue &rhs) const
Compare memory queues.
Definition os-mqueue.h:1281
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59
port::clock::duration_t duration_t
Type of variables holding clock durations.
Definition os-clocks.h:78
static constexpr msg_size_t max_msg_size
Maximum message size.
Definition os-mqueue.h:102
static constexpr priority_t max_priority
Maximum message priority.
Definition os-mqueue.h:144
uint8_t priority_t
Type of message priority storage.
Definition os-mqueue.h:125
message_queue::size_t index_t
Type of list index storage.
Definition os-mqueue.h:108
static constexpr priority_t default_priority
Default message priority.
Definition os-mqueue.h:134
static const attributes initializer
Default message queue initialiser.
Definition os-mqueue.h:217
uint8_t size_t
Type of a queue size storage.
Definition os-mqueue.h:83
memory::allocator< thread::stack::allocation_element_t > allocator_type
Default RTOS allocator.
Definition os-mqueue.h:224
uint16_t msg_size_t
Type of message size storage.
Definition os-mqueue.h:96
static constexpr index_t no_index
Index value to represent an illegal index.
Definition os-mqueue.h:114
static constexpr message_queue::size_t max_size
Maximum queue size.
Definition os-mqueue.h:90
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:95
System namespace.