µ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++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2016-2023 Liviu Ionescu. All rights reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software
7 * for any purpose is hereby granted, under the terms of the MIT license.
8 *
9 * If a copy of the license was not distributed with this file, it can
10 * be obtained from https://opensource.org/licenses/mit/.
11 */
12
13#ifndef CMSIS_PLUS_RTOS_OS_MQUEUE_H_
14#define CMSIS_PLUS_RTOS_OS_MQUEUE_H_
15
16// ----------------------------------------------------------------------------
17
18#if defined(__cplusplus)
19
20// ----------------------------------------------------------------------------
21
22#if defined(OS_USE_OS_APP_CONFIG_H)
23#include <cmsis-plus/os-app-config.h>
24#endif
25
28
30
31// ----------------------------------------------------------------------------
32
33#pragma GCC diagnostic push
34#if defined(__clang__)
35#pragma clang diagnostic ignored "-Wc++98-compat"
36#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
37#endif
38
39// ----------------------------------------------------------------------------
40
41namespace os
42{
43 namespace rtos
44 {
45
46 // ========================================================================
47
48#pragma GCC diagnostic push
49#if defined(__clang__)
50#pragma clang diagnostic ignored "-Wpadded"
51#elif defined(__GNUC__)
52#pragma GCC diagnostic ignored "-Wpadded"
53#endif
54
61#pragma GCC diagnostic push
62#if defined(__clang__)
63#elif defined(__GNUC__)
64#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
65#pragma GCC diagnostic ignored "-Wsuggest-final-types"
66#endif
68 {
69 public:
70
71 // ======================================================================
72
81#if defined(OS_BOOL_RTOS_MESSAGE_QUEUE_SIZE_16BITS)
82 using size_t = uint16_t;
83#else
84 using size_t = uint8_t;
85#endif
86
91 static constexpr message_queue::size_t max_size = 0xFF;
92
97 using msg_size_t = uint16_t;
98
103 static constexpr msg_size_t max_msg_size = 0xFFFF;
104
110
115 static constexpr index_t no_index = max_size;
116
125 using priority_t = uint8_t;
126
133 static constexpr priority_t default_priority = 0;
134
142 static constexpr priority_t max_priority = 0xFF;
143
144 // ======================================================================
145
152 {
153 public:
154
165 constexpr
166 attributes ();
167
168 // The rule of five.
169 attributes (const attributes&) = default;
170 attributes (attributes&&) = default;
172 operator= (const attributes&) = default;
174 operator= (attributes&&) = default;
175
179 ~attributes () = default;
180
185 public:
186
192 // Public members; no accessors and mutators required.
193 // Warning: must match the type & order of the C file header.
197 void* mq_queue_address = nullptr;
198
202 std::size_t mq_queue_size_bytes = 0;
203
204 // Add more attributes here.
205
210 }; /* class attributes */
211
217
223
232 template<typename T, std::size_t msgs, std::size_t msg_size_bytes>
233 class arena
234 {
235 public:
236 T queue[(msgs * msg_size_bytes + sizeof(T) - 1) / sizeof(T)];
237 T links[((2 * msgs) * sizeof(index_t) + sizeof(T) - 1) / sizeof(T)];
238 T prios[(msgs * sizeof(priority_t) + sizeof(T) - 1) / sizeof(T)];
239 };
240
248 template<typename T>
249 constexpr std::size_t
251 std::size_t msg_size_bytes)
252 {
253 // Align each message
254 return (msgs * ((msg_size_bytes + (sizeof(T) - 1)) & ~(sizeof(T) - 1)))
255 // Align the indices array
256 + ((2 * msgs * sizeof(index_t) + (sizeof(T) - 1))
257 & ~(sizeof(T) - 1))
258 // Align the priority array
259 + ((msgs * sizeof(priority_t) + (sizeof(T) - 1))
260 & ~(sizeof(T) - 1));
261 }
262
263 // ======================================================================
264
278 message_queue (std::size_t msgs, std::size_t msg_size_bytes,
279 const attributes& attr = initializer,
280 const allocator_type& allocator = allocator_type ());
281
291 message_queue (const char* name, std::size_t msgs,
292 std::size_t msg_size_bytes, const attributes& attr =
294 const allocator_type& allocator = allocator_type ());
295
296 protected:
297
302 // Internal constructors, used from templates.
303 message_queue ();
304 message_queue (const char* name);
305
310 public:
311
316 // The rule of five.
317 message_queue (const message_queue&) = delete;
318 message_queue (message_queue&&) = delete;
320 operator= (const message_queue&) = delete;
322 operator= (message_queue&&) = delete;
323
331 virtual
333
348 bool
349 operator== (const message_queue& rhs) const;
350
355 public:
356
378 send (const void* msg, std::size_t nbytes, priority_t mprio =
380
396 try_send (const void* msg, std::size_t nbytes, priority_t mprio =
398
418 timed_send (const void* msg, std::size_t nbytes,
419 clock::duration_t timeout,
421
441 receive (void* msg, std::size_t nbytes, priority_t* mprio = nullptr);
442
461 try_receive (void* msg, std::size_t nbytes, priority_t* mprio = nullptr);
462
485 timed_receive (void* msg, std::size_t nbytes, clock::duration_t timeout,
486 priority_t* mprio = nullptr);
487
488 // TODO: check if some kind of peek() is useful.
489
496 std::size_t
497 capacity (void) const;
498
505 std::size_t
506 length (void) const;
507
514 std::size_t
515 msg_size (void) const;
516
524 bool
525 empty (void) const;
526
534 bool
535 full (void) const;
536
545 reset (void);
546
551 protected:
552
572 void
573 internal_construct_ (std::size_t msgs, std::size_t msg_size_bytes,
574 const attributes& attr, void* queue_address,
575 std::size_t queue_size_bytes);
576
584 void
585 internal_init_ (void);
586
587#if !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE)
588
598 bool
599 internal_try_send_ (const void* msg, std::size_t nbytes,
600 priority_t mprio);
601
612 bool
613 internal_try_receive_ (void* msg, std::size_t nbytes, priority_t* mprio);
614
615#endif /* !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE) */
616
625 protected:
626
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
675 void* volatile first_free_ = nullptr;
676#endif /* !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE) */
677
682 void* queue_addr_ = nullptr;
687 void* allocated_queue_addr_ = nullptr;
691 const void* allocator_ = nullptr;
692
693#if defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE)
694 friend class port::message_queue;
695 os_mqueue_port_data_t port_;
696#endif
697
702 std::size_t queue_size_bytes_ = 0;
706 std::size_t allocated_queue_size_elements_ = 0;
707
711 message_queue::msg_size_t msg_size_bytes_ = 0;
715 message_queue::size_t msgs_ = 0;
719 message_queue::size_t count_ = 0;
720
721#if !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE)
725 index_t head_ = 0;
726#endif /* !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE) */
727
736 };
737#pragma GCC diagnostic pop
738
739 // ========================================================================
740
746 template<typename Allocator = memory::allocator<void*>>
748 {
749 public:
750
754 using allocator_type = Allocator;
755
769 message_queue_allocated (std::size_t msgs, std::size_t msg_size_bytes,
770 const attributes& attr = initializer,
771 const allocator_type& allocator =
772 allocator_type ());
773
783 message_queue_allocated (const char* name, std::size_t msgs,
784 std::size_t msg_size_bytes,
785 const attributes& attr = initializer,
786 const allocator_type& allocator =
787 allocator_type ());
788
789 public:
790
795 // The rule of five.
799 operator= (const message_queue_allocated&) = delete;
801 operator= (message_queue_allocated&&) = delete;
802
810 virtual
812
817 };
818
819 // ========================================================================
820
827#pragma GCC diagnostic push
828#if defined(__clang__)
829#elif defined(__GNUC__)
830#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
831#pragma GCC diagnostic ignored "-Wsuggest-final-types"
832#endif
833 template<typename T, typename Allocator = memory::allocator<void*>>
835 {
836 public:
837
841 using value_type = T;
842
846 using allocator_type = Allocator;
847
860 message_queue_typed (std::size_t msgs,
861 const message_queue::attributes& attr =
863 const allocator_type& allocator =
864 allocator_type ());
865
874 message_queue_typed (const char* name, std::size_t msgs,
875 const message_queue::attributes& attr =
877 const allocator_type& allocator =
878 allocator_type ());
879
884 // The rule of five.
888 operator= (const message_queue_typed&) = delete;
890 operator= (message_queue_typed&&) = delete;
891
899 virtual
900 ~message_queue_typed () override;
901
906 public:
907
927 send (const value_type* msg, message_queue::priority_t mprio =
929
946
964 timed_send (const value_type* msg, clock::duration_t timeout,
967
985 receive (value_type* msg, message_queue::priority_t* mprio = nullptr);
986
1003 result_t
1004 try_receive (value_type* msg,
1005 message_queue::priority_t* mprio = nullptr);
1006
1026 result_t
1028 message_queue::priority_t* mprio = nullptr);
1029
1034 };
1035#pragma GCC diagnostic pop
1036
1037 // ========================================================================
1038
1045 template<typename T, std::size_t N>
1047 {
1048 public:
1049
1053 using value_type = T;
1054
1058 static const std::size_t msgs = N;
1059
1070
1076 message_queue_inclusive (const char* name, const attributes& attr =
1077 initializer);
1078
1083 // The rule of five.
1087 operator= (const message_queue_inclusive&) = delete;
1089 operator= (message_queue_inclusive&&) = delete;
1090
1098 virtual
1099 ~message_queue_inclusive () override;
1100
1105 public:
1106
1125 result_t
1126 send (const value_type* msg, priority_t mprio = default_priority);
1127
1141 result_t
1142 try_send (const value_type* msg, priority_t mprio = default_priority);
1143
1160 result_t
1161 timed_send (const value_type* msg, clock::duration_t timeout,
1163
1180 result_t
1181 receive (value_type* msg, priority_t* mprio = nullptr);
1182
1199 result_t
1200 try_receive (value_type* msg, priority_t* mprio = nullptr);
1201
1221 result_t
1223 priority_t* mprio = nullptr);
1224
1229 protected:
1230
1249 arena<void*, msgs, sizeof(value_type)> arena_;
1250
1259 };
1260
1261#pragma GCC diagnostic pop
1262
1263 }
1264/* namespace rtos */
1265} /* namespace os */
1266
1267// ===== Inline & template implementations ====================================
1268
1269namespace os
1270{
1271 namespace rtos
1272 {
1273 constexpr
1275 {
1276 }
1277
1278 // ========================================================================
1279
1287 inline bool
1289 {
1290 return this == &rhs;
1291 }
1292
1299 inline std::size_t
1301 {
1302 return count_;
1303 }
1304
1311 inline std::size_t
1313 {
1314 return msgs_;
1315 }
1316
1323 inline std::size_t
1325 {
1326 return msg_size_bytes_;
1327 }
1328
1335 inline bool
1337 {
1338 return (length () == 0);
1339 }
1340
1347 inline bool
1349 {
1350 return (length () == capacity ());
1351 }
1352
1353 // ========================================================================
1354
1381 template<typename Allocator>
1382 inline
1384 std::size_t msgs, std::size_t msg_size_bytes, const attributes& attr,
1385 const allocator_type& allocator) :
1387 { nullptr, msgs, msg_size_bytes, attr, allocator }
1388 {
1389 }
1390
1417 template<typename Allocator>
1419 const char* name, std::size_t msgs, std::size_t msg_size_bytes,
1420 const attributes& attr, const allocator_type& allocator) :
1422 { name }
1423 {
1424#if defined(OS_TRACE_RTOS_MQUEUE)
1425 trace::printf ("%s() @%p %s %d %d\n", __func__, this, this->name (),
1426 msgs, msg_size_bytes);
1427#endif
1428
1429 if (attr.mq_queue_address != nullptr)
1430 {
1431 // Do not use any allocator at all.
1432 internal_construct_ (msgs, msg_size_bytes, attr, nullptr, 0);
1433 }
1434 else
1435 {
1436 allocator_ = &allocator;
1437
1438 // If no user storage was provided via attributes,
1439 // allocate it dynamically via the allocator.
1440 allocated_queue_size_elements_ = (compute_allocated_size_bytes<
1441 typename allocator_type::value_type> (msgs, msg_size_bytes)
1442 + sizeof(typename allocator_type::value_type) - 1)
1443 / sizeof(typename allocator_type::value_type);
1444
1445 allocated_queue_addr_ =
1446 const_cast<allocator_type&> (allocator).allocate (
1447 allocated_queue_size_elements_);
1448
1449 internal_construct_ (
1450 msgs,
1451 msg_size_bytes,
1452 attr,
1453 allocated_queue_addr_,
1454 allocated_queue_size_elements_
1455 * sizeof(typename allocator_type::value_type));
1456 }
1457 }
1458
1473 template<typename Allocator>
1475 {
1476#if defined(OS_TRACE_RTOS_MQUEUE)
1477 trace::printf ("%s() @%p %s\n", __func__, this, name ());
1478#endif
1479 typedef typename std::allocator_traits<allocator_type>::pointer pointer;
1480
1481 if (allocated_queue_addr_ != nullptr)
1482 {
1483 static_cast<allocator_type*> (const_cast<void*> (allocator_))->deallocate (
1484 static_cast<pointer> (allocated_queue_addr_),
1485 allocated_queue_size_elements_);
1486
1487 allocated_queue_addr_ = nullptr;
1488 }
1489 }
1490
1491 // ========================================================================
1492
1522 template<typename T, typename Allocator>
1523 inline
1525 std::size_t msgs, const message_queue::attributes& attr,
1526 const allocator_type& allocator) :
1528 { msgs, sizeof(value_type), attr, allocator }
1529 {
1530 }
1531
1561 template<typename T, typename Allocator>
1562 inline
1564 const char* name, std::size_t msgs,
1565 const message_queue::attributes& attr,
1566 const allocator_type& allocator) :
1568 { name, msgs, sizeof(value_type), attr, allocator }
1569 {
1570 }
1571
1588#pragma GCC diagnostic push
1589#if defined(__clang__)
1590#elif defined(__GNUC__)
1591#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
1592#endif
1593 template<typename T, typename Allocator>
1595 {
1596 }
1597#pragma GCC diagnostic pop
1598
1606 template<typename T, typename Allocator>
1607 inline result_t
1610 {
1612 reinterpret_cast<const char*> (msg), sizeof(value_type), mprio);
1613 }
1614
1622 template<typename T, typename Allocator>
1623 inline result_t
1625 const value_type* msg, message_queue::priority_t mprio)
1626 {
1628 reinterpret_cast<const char*> (msg), sizeof(value_type), mprio);
1629 }
1630
1638 template<typename T, typename Allocator>
1639 inline result_t
1641 const value_type* msg, clock::duration_t timeout,
1643 {
1645 reinterpret_cast<const char*> (msg), sizeof(value_type), timeout,
1646 mprio);
1647 }
1648
1656 template<typename T, typename Allocator>
1657 inline result_t
1660 {
1662 reinterpret_cast<char*> (msg), sizeof(value_type), mprio);
1663 }
1664
1672 template<typename T, typename Allocator>
1673 inline result_t
1676 {
1678 reinterpret_cast<char*> (msg), sizeof(value_type), mprio);
1679 }
1680
1688 template<typename T, typename Allocator>
1689 inline result_t
1691 value_type* msg, clock::duration_t timeout,
1693 {
1695 reinterpret_cast<char*> (msg), sizeof(value_type), timeout, mprio);
1696 }
1697
1698 // ========================================================================
1699
1734 template<typename T, std::size_t N>
1735 inline
1737 const attributes& attr) :
1739 { nullptr, attr }
1740 {
1741 }
1742
1777 template<typename T, std::size_t N>
1779 const char* name, const attributes& attr) :
1780 message_queue (name)
1781 {
1782 static_assert(sizeof(T) >= sizeof(void*), "Messages of message_queue need to have at least the size of a pointer");
1783
1784 internal_construct_ (msgs, sizeof(value_type), attr, &arena_,
1785 sizeof(arena_));
1786 }
1787
1801 template<typename T, std::size_t N>
1803 {
1804 }
1805
1813 template<typename T, std::size_t N>
1814 inline result_t
1816 priority_t mprio)
1817 {
1818 return message_queue::send (reinterpret_cast<const char*> (msg),
1819 sizeof(value_type), mprio);
1820 }
1821
1829 template<typename T, std::size_t N>
1830 inline result_t
1832 priority_t mprio)
1833 {
1834 return message_queue::try_send (reinterpret_cast<const char*> (msg),
1835 sizeof(value_type), mprio);
1836 }
1837
1845 template<typename T, std::size_t N>
1846 inline result_t
1848 clock::duration_t timeout,
1849 priority_t mprio)
1850 {
1851 return message_queue::timed_send (reinterpret_cast<const char*> (msg),
1852 sizeof(value_type), timeout, mprio);
1853 }
1854
1862 template<typename T, std::size_t N>
1863 inline result_t
1865 priority_t* mprio)
1866 {
1867 return message_queue::receive (reinterpret_cast<char*> (msg),
1868 sizeof(value_type), mprio);
1869 }
1870
1878 template<typename T, std::size_t N>
1879 inline result_t
1881 priority_t* mprio)
1882 {
1883 return message_queue::try_receive (reinterpret_cast<char*> (msg),
1884 sizeof(value_type), mprio);
1885 }
1886
1894 template<typename T, std::size_t N>
1895 inline result_t
1897 clock::duration_t timeout,
1898 priority_t* mprio)
1899 {
1900 return message_queue::timed_receive (reinterpret_cast<char*> (msg),
1901 sizeof(value_type), timeout, mprio);
1902 }
1903
1904 } /* namespace rtos */
1905} /* namespace os */
1906
1907#pragma GCC diagnostic pop
1908
1909// ----------------------------------------------------------------------------
1910
1911#endif /* __cplusplus */
1912
1913// ----------------------------------------------------------------------------
1914
1915#endif /* CMSIS_PLUS_RTOS_OS_MQUEUE_H_ */
Generic clock.
Definition os-clocks.h:59
Base class for attributes.
Definition os-decls.h:563
Base class for named system objects.
Definition os-decls.h:445
const char * name(void) const
Get object name.
Definition os-decls.h:759
Priority ordered list of threads.
Definition os-lists.h:550
Standard allocator based on the RTOS system default memory manager.
Definition os-memory.h:540
Storage for a static message queue.
Definition os-mqueue.h:234
T prios[(msgs *sizeof(priority_t)+sizeof(T) - 1)/sizeof(T)]
Definition os-mqueue.h:238
T queue[(msgs *msg_size_bytes+sizeof(T) - 1)/sizeof(T)]
Definition os-mqueue.h:236
T links[((2 *msgs) *sizeof(index_t)+sizeof(T) - 1)/sizeof(T)]
Definition os-mqueue.h:237
Message queue attributes.
Definition os-mqueue.h:152
attributes(attributes &&)=default
attributes(const attributes &)=default
constexpr attributes()
Construct a message queue attributes object instance.
Definition os-mqueue.h:1274
void * mq_queue_address
Address of the user defined storage for the message queue.
Definition os-mqueue.h:197
std::size_t mq_queue_size_bytes
Size of the user defined storage for the message queue.
Definition os-mqueue.h:202
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:1383
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:1418
virtual ~message_queue_allocated() override
Destruct the message queue.
Definition os-mqueue.h:1474
Allocator allocator_type
Standard allocator type definition.
Definition os-mqueue.h:754
Template of a POSIX compliant message queue with message type and local storage.
Definition os-mqueue.h:1047
T value_type
Local type of message.
Definition os-mqueue.h:1053
result_t send(const value_type *msg, priority_t mprio=default_priority)
Send a typed message to the queue.
Definition os-mqueue.h:1815
virtual ~message_queue_inclusive() override
Destruct the typed message queue object instance.
Definition os-mqueue.h:1802
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:1831
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:1847
message_queue_inclusive(const attributes &attr=initializer)
Construct a typed message queue object instance.
Definition os-mqueue.h:1736
static const std::size_t msgs
Local constant based on template definition.
Definition os-mqueue.h:1058
result_t receive(value_type *msg, priority_t *mprio=nullptr)
Receive a typed message from the queue.
Definition os-mqueue.h:1864
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:1896
result_t try_receive(value_type *msg, priority_t *mprio=nullptr)
Try to receive a typed message from the queue.
Definition os-mqueue.h:1880
Template of a POSIX compliant message queue with message type and allocator.
Definition os-mqueue.h:835
T value_type
Standard allocator type definition.
Definition os-mqueue.h:841
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:1608
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:1624
Allocator allocator_type
Standard allocator type definition.
Definition os-mqueue.h:846
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:1674
result_t receive(value_type *msg, message_queue::priority_t *mprio=nullptr)
Receive a typed message from the queue.
Definition os-mqueue.h:1658
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:1690
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:1524
virtual ~message_queue_typed() override
Destruct the typed message queue object instance.
Definition os-mqueue.h:1594
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:1640
POSIX compliant message queue, using the default RTOS allocator.
Definition os-mqueue.h:68
bool empty(void) const
Check if the queue is empty.
Definition os-mqueue.h:1336
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:1312
std::size_t msg_size(void) const
Get message size.
Definition os-mqueue.h:1324
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:250
bool full(void) const
Check if the queue is full.
Definition os-mqueue.h:1348
std::size_t length(void) const
Get queue length.
Definition os-mqueue.h:1300
bool operator==(const message_queue &rhs) const
Compare memory queues.
Definition os-mqueue.h:1288
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:60
port::clock::duration_t duration_t
Type of variables holding clock durations.
Definition os-clocks.h:76
static constexpr msg_size_t max_msg_size
Maximum message size.
Definition os-mqueue.h:103
static constexpr priority_t max_priority
Maximum message priority.
Definition os-mqueue.h:142
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:109
static constexpr priority_t default_priority
Default message priority.
Definition os-mqueue.h:133
static const attributes initializer
Default message queue initialiser.
Definition os-mqueue.h:216
uint8_t size_t
Type of a queue size storage.
Definition os-mqueue.h:84
memory::allocator< thread::stack::allocation_element_t > allocator_type
Default RTOS allocator.
Definition os-mqueue.h:222
uint16_t msg_size_t
Type of message size storage.
Definition os-mqueue.h:97
static constexpr index_t no_index
Index value to represent an illegal index.
Definition os-mqueue.h:115
static constexpr message_queue::size_t max_size
Maximum queue size.
Definition os-mqueue.h:91
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:96
System namespace.