µ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 Liviu Ionescu.
5 *
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following
13 * conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
28#ifndef CMSIS_PLUS_RTOS_OS_MQUEUE_H_
29#define CMSIS_PLUS_RTOS_OS_MQUEUE_H_
30
31// ----------------------------------------------------------------------------
32
33#if defined(__cplusplus)
34
35// ----------------------------------------------------------------------------
36
39
41
42// ----------------------------------------------------------------------------
43
44#pragma GCC diagnostic push
45
46#if defined(__clang__)
47#pragma clang diagnostic ignored "-Wc++98-compat"
48#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
49#endif
50
51// ----------------------------------------------------------------------------
52
53namespace os
54{
55 namespace rtos
56 {
57
58 // ========================================================================
59
60#pragma GCC diagnostic push
61#pragma GCC diagnostic ignored "-Wpadded"
62
70 {
71 public:
72
73 // ======================================================================
74
83#if defined(OS_BOOL_RTOS_MESSAGE_QUEUE_SIZE_16BITS)
84 using size_t = uint16_t;
85#else
86 using size_t = uint8_t;
87#endif
88
93 static constexpr message_queue::size_t max_size = 0xFF;
94
99 using msg_size_t = uint16_t;
100
105 static constexpr msg_size_t max_msg_size = 0xFFFF;
106
112
117 static constexpr index_t no_index = max_size;
118
127 using priority_t = uint8_t;
128
135 static constexpr priority_t default_priority = 0;
136
144 static constexpr priority_t max_priority = 0xFF;
145
146 // ======================================================================
147
154 {
155 public:
156
167 constexpr
168 attributes ();
169
170 // The rule of five.
171 attributes (const attributes&) = default;
172 attributes (attributes&&) = default;
174 operator= (const attributes&) = default;
176 operator= (attributes&&) = default;
177
181 ~attributes () = default;
182
187 public:
188
194 // Public members; no accessors and mutators required.
195 // Warning: must match the type & order of the C file header.
199 void* mq_queue_address = nullptr;
200
204 std::size_t mq_queue_size_bytes = 0;
205
206 // Add more attributes here.
207
212 }; /* class attributes */
213
219
225
234 template<typename T, std::size_t msgs, std::size_t msg_size_bytes>
235 class arena
236 {
237 public:
238 T queue[(msgs * msg_size_bytes + sizeof(T) - 1) / sizeof(T)];
239 T links[((2 * msgs) * sizeof(index_t) + sizeof(T) - 1) / sizeof(T)];
240 T prios[(msgs * sizeof(priority_t) + sizeof(T) - 1) / sizeof(T)];
241 };
242
250 template<typename T>
251 constexpr std::size_t
253 std::size_t msg_size_bytes)
254 {
255 // Align each message
256 return (msgs * ((msg_size_bytes + (sizeof(T) - 1)) & ~(sizeof(T) - 1)))
257 // Align the indices array
258 + ((2 * msgs * sizeof(index_t) + (sizeof(T) - 1))
259 & ~(sizeof(T) - 1))
260 // Align the priority array
261 + ((msgs * sizeof(priority_t) + (sizeof(T) - 1))
262 & ~(sizeof(T) - 1));
263 }
264
265 // ======================================================================
266
280 message_queue (std::size_t msgs, std::size_t msg_size_bytes,
281 const attributes& attr = initializer,
282 const allocator_type& allocator = allocator_type ());
283
293 message_queue (const char* name, std::size_t msgs,
294 std::size_t msg_size_bytes, const attributes& attr =
296 const allocator_type& allocator = allocator_type ());
297
298 protected:
299
304 // Internal constructors, used from templates.
305 message_queue ();
306 message_queue (const char* name);
307
312 public:
313
318 // The rule of five.
319 message_queue (const message_queue&) = delete;
320 message_queue (message_queue&&) = delete;
322 operator= (const message_queue&) = delete;
324 operator= (message_queue&&) = delete;
325
333 virtual
335
350 bool
351 operator== (const message_queue& rhs) const;
352
357 public:
358
380 send (const void* msg, std::size_t nbytes, priority_t mprio =
382
398 try_send (const void* msg, std::size_t nbytes, priority_t mprio =
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:
554
574 void
575 internal_construct_ (std::size_t msgs, std::size_t msg_size_bytes,
576 const attributes& attr, void* queue_address,
577 std::size_t queue_size_bytes);
578
586 void
587 internal_init_ (void);
588
589#if !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE)
590
600 bool
601 internal_try_send_ (const void* msg, std::size_t nbytes,
602 priority_t mprio);
603
614 bool
615 internal_try_receive_ (void* msg, std::size_t nbytes, priority_t* mprio);
616
617#endif /* !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE) */
618
627 protected:
628
638 // Keep these in sync with the structure declarations in os-c-decl.h.
639#if !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE)
647 internal::waiting_threads_list receive_list_;
651 clock* clock_ = nullptr;
652
653 // To save space, the double linked list is built
654 // using short indexes, not pointers.
658 volatile index_t* prev_array_ = nullptr;
662 volatile index_t* next_array_ = nullptr;
666 volatile priority_t* prio_array_ = nullptr;
667
677 void* volatile first_free_ = nullptr;
678#endif /* !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE) */
679
684 void* queue_addr_ = nullptr;
689 void* allocated_queue_addr_ = nullptr;
693 const void* allocator_ = nullptr;
694
695#if defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE)
696 friend class port::message_queue;
697 os_mqueue_port_data_t port_;
698#endif
699
704 std::size_t queue_size_bytes_ = 0;
708 std::size_t allocated_queue_size_elements_ = 0;
709
713 message_queue::msg_size_t msg_size_bytes_ = 0;
717 message_queue::size_t msgs_ = 0;
721 message_queue::size_t count_ = 0;
722
723#if !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE)
727 index_t head_ = 0;
728#endif /* !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE) */
729
738 };
739
740 // ========================================================================
741
747 template<typename Allocator = memory::allocator<void*>>
749 {
750 public:
751
755 using allocator_type = Allocator;
756
770 message_queue_allocated (std::size_t msgs, std::size_t msg_size_bytes,
771 const attributes& attr = initializer,
772 const allocator_type& allocator =
773 allocator_type ());
774
784 message_queue_allocated (const char* name, std::size_t msgs,
785 std::size_t msg_size_bytes,
786 const attributes& attr = initializer,
787 const allocator_type& allocator =
788 allocator_type ());
789
790 public:
791
796 // The rule of five.
800 operator= (const message_queue_allocated&) = delete;
802 operator= (message_queue_allocated&&) = delete;
803
811 virtual
813
818 };
819
820 // ========================================================================
821
828 template<typename T, typename Allocator = memory::allocator<void*>>
830 {
831 public:
832
836 using value_type = T;
837
841 using allocator_type = Allocator;
842
855 message_queue_typed (std::size_t msgs,
856 const message_queue::attributes& attr =
858 const allocator_type& allocator =
859 allocator_type ());
860
869 message_queue_typed (const char* name, std::size_t msgs,
870 const message_queue::attributes& attr =
872 const allocator_type& allocator =
873 allocator_type ());
874
879 // The rule of five.
883 operator= (const message_queue_typed&) = delete;
885 operator= (message_queue_typed&&) = delete;
886
894 virtual
895 ~message_queue_typed () override;
896
901 public:
902
922 send (const value_type* msg, message_queue::priority_t mprio =
924
941
959 timed_send (const value_type* msg, clock::duration_t timeout,
962
980 receive (value_type* msg, message_queue::priority_t* mprio = nullptr);
981
1000 message_queue::priority_t* mprio = nullptr);
1001
1021 result_t
1023 message_queue::priority_t* mprio = nullptr);
1024
1029 };
1030
1031 // ========================================================================
1032
1039 template<typename T, std::size_t N>
1041 {
1042 public:
1043
1047 using value_type = T;
1048
1052 static const std::size_t msgs = N;
1053
1064
1070 message_queue_inclusive (const char* name, const attributes& attr =
1071 initializer);
1072
1077 // The rule of five.
1081 operator= (const message_queue_inclusive&) = delete;
1083 operator= (message_queue_inclusive&&) = delete;
1084
1092 virtual
1093 ~message_queue_inclusive () override;
1094
1099 public:
1100
1119 result_t
1120 send (const value_type* msg, priority_t mprio = default_priority);
1121
1135 result_t
1136 try_send (const value_type* msg, priority_t mprio = default_priority);
1137
1154 result_t
1155 timed_send (const value_type* msg, clock::duration_t timeout,
1157
1174 result_t
1175 receive (value_type* msg, priority_t* mprio = nullptr);
1176
1193 result_t
1194 try_receive (value_type* msg, priority_t* mprio = nullptr);
1195
1215 result_t
1217 priority_t* mprio = nullptr);
1218
1223 protected:
1224
1243 arena<void*, msgs, sizeof(value_type)> arena_;
1244
1253 };
1254
1255#pragma GCC diagnostic pop
1256
1257 }
1258/* namespace rtos */
1259} /* namespace os */
1260
1261// ===== Inline & template implementations ====================================
1262
1263namespace os
1264{
1265 namespace rtos
1266 {
1267 constexpr
1269 {
1270 ;
1271 }
1272
1273 // ========================================================================
1274
1282 inline bool
1284 {
1285 return this == &rhs;
1286 }
1287
1294 inline std::size_t
1296 {
1297 return count_;
1298 }
1299
1306 inline std::size_t
1308 {
1309 return msgs_;
1310 }
1311
1318 inline std::size_t
1320 {
1321 return msg_size_bytes_;
1322 }
1323
1330 inline bool
1332 {
1333 return (length () == 0);
1334 }
1335
1342 inline bool
1344 {
1345 return (length () == capacity ());
1346 }
1347
1348 // ========================================================================
1349
1376 template<typename Allocator>
1377 inline
1379 std::size_t msgs, std::size_t msg_size_bytes, const attributes& attr,
1380 const allocator_type& allocator) :
1382 { nullptr, msgs, msg_size_bytes, attr, allocator }
1383 {
1384 ;
1385 }
1386
1413 template<typename Allocator>
1415 const char* name, std::size_t msgs, std::size_t msg_size_bytes,
1416 const attributes& attr, const allocator_type& allocator) :
1418 { name }
1419 {
1420#if defined(OS_TRACE_RTOS_MQUEUE)
1421 trace::printf ("%s() @%p %s %d %d\n", __func__, this, this->name (),
1422 msgs, msg_size_bytes);
1423#endif
1424
1425 if (attr.mq_queue_address != nullptr)
1426 {
1427 // Do not use any allocator at all.
1428 internal_construct_ (msgs, msg_size_bytes, attr, nullptr, 0);
1429 }
1430 else
1431 {
1432 allocator_ = &allocator;
1433
1434 // If no user storage was provided via attributes,
1435 // allocate it dynamically via the allocator.
1436 allocated_queue_size_elements_ = (compute_allocated_size_bytes<
1437 typename allocator_type::value_type> (msgs, msg_size_bytes)
1438 + sizeof(typename allocator_type::value_type) - 1)
1439 / sizeof(typename allocator_type::value_type);
1440
1441 allocated_queue_addr_ =
1442 const_cast<allocator_type&> (allocator).allocate (
1443 allocated_queue_size_elements_);
1444
1445 internal_construct_ (
1446 msgs,
1447 msg_size_bytes,
1448 attr,
1449 allocated_queue_addr_,
1450 allocated_queue_size_elements_
1451 * sizeof(typename allocator_type::value_type));
1452 }
1453 }
1454
1469 template<typename Allocator>
1471 {
1472#if defined(OS_TRACE_RTOS_MQUEUE)
1473 trace::printf ("%s() @%p %s\n", __func__, this, name ());
1474#endif
1475 typedef typename std::allocator_traits<allocator_type>::pointer pointer;
1476
1477 if (allocated_queue_addr_ != nullptr)
1478 {
1479 static_cast<allocator_type*> (const_cast<void*> (allocator_))->deallocate (
1480 static_cast<pointer> (allocated_queue_addr_),
1481 allocated_queue_size_elements_);
1482
1483 allocated_queue_addr_ = nullptr;
1484 }
1485 }
1486
1487 // ========================================================================
1488
1518 template<typename T, typename Allocator>
1519 inline
1521 std::size_t msgs, const message_queue::attributes& attr,
1522 const allocator_type& allocator) :
1524 { msgs, sizeof(value_type), attr, allocator }
1525 {
1526 ;
1527 }
1528
1558 template<typename T, typename Allocator>
1559 inline
1561 const char* name, std::size_t msgs,
1562 const message_queue::attributes& attr,
1563 const allocator_type& allocator) :
1565 { name, msgs, sizeof(value_type), attr, allocator }
1566 {
1567 ;
1568 }
1569
1586 template<typename T, typename Allocator>
1588 {
1589 ;
1590 }
1591
1599 template<typename T, typename Allocator>
1600 inline result_t
1603 {
1605 reinterpret_cast<const char*> (msg), sizeof(value_type), mprio);
1606 }
1607
1615 template<typename T, typename Allocator>
1616 inline result_t
1618 const value_type* msg, message_queue::priority_t mprio)
1619 {
1621 reinterpret_cast<const char*> (msg), sizeof(value_type), mprio);
1622 }
1623
1631 template<typename T, typename Allocator>
1632 inline result_t
1634 const value_type* msg, clock::duration_t timeout,
1636 {
1638 reinterpret_cast<const char*> (msg), sizeof(value_type), timeout,
1639 mprio);
1640 }
1641
1649 template<typename T, typename Allocator>
1650 inline result_t
1653 {
1655 reinterpret_cast<char*> (msg), sizeof(value_type), mprio);
1656 }
1657
1665 template<typename T, typename Allocator>
1666 inline result_t
1669 {
1671 reinterpret_cast<char*> (msg), sizeof(value_type), mprio);
1672 }
1673
1681 template<typename T, typename Allocator>
1682 inline result_t
1684 value_type* msg, clock::duration_t timeout,
1686 {
1688 reinterpret_cast<char*> (msg), sizeof(value_type), timeout, mprio);
1689 }
1690
1691 // ========================================================================
1692
1727 template<typename T, std::size_t N>
1728 inline
1730 const attributes& attr) :
1732 { nullptr, attr }
1733 {
1734 ;
1735 }
1736
1771 template<typename T, std::size_t N>
1773 const char* name, const attributes& attr) :
1774 message_queue (name)
1775 {
1776 static_assert(sizeof(T) >= sizeof(void*), "Messages of message_queue need to have at least the size of a pointer");
1777
1778 internal_construct_ (msgs, sizeof(value_type), attr, &arena_,
1779 sizeof(arena_));
1780 }
1781
1795 template<typename T, std::size_t N>
1797 {
1798 ;
1799 }
1800
1808 template<typename T, std::size_t N>
1809 inline result_t
1811 priority_t mprio)
1812 {
1813 return message_queue::send (reinterpret_cast<const char*> (msg),
1814 sizeof(value_type), mprio);
1815 }
1816
1824 template<typename T, std::size_t N>
1825 inline result_t
1827 priority_t mprio)
1828 {
1829 return message_queue::try_send (reinterpret_cast<const char*> (msg),
1830 sizeof(value_type), mprio);
1831 }
1832
1840 template<typename T, std::size_t N>
1841 inline result_t
1843 clock::duration_t timeout,
1844 priority_t mprio)
1845 {
1846 return message_queue::timed_send (reinterpret_cast<const char*> (msg),
1847 sizeof(value_type), timeout, mprio);
1848 }
1849
1857 template<typename T, std::size_t N>
1858 inline result_t
1860 priority_t* mprio)
1861 {
1862 return message_queue::receive (reinterpret_cast<char*> (msg),
1863 sizeof(value_type), mprio);
1864 }
1865
1873 template<typename T, std::size_t N>
1874 inline result_t
1876 priority_t* mprio)
1877 {
1878 return message_queue::try_receive (reinterpret_cast<char*> (msg),
1879 sizeof(value_type), mprio);
1880 }
1881
1889 template<typename T, std::size_t N>
1890 inline result_t
1892 clock::duration_t timeout,
1893 priority_t* mprio)
1894 {
1895 return message_queue::timed_receive (reinterpret_cast<char*> (msg),
1896 sizeof(value_type), timeout, mprio);
1897 }
1898
1899 } /* namespace rtos */
1900} /* namespace os */
1901
1902#pragma GCC diagnostic pop
1903
1904// ----------------------------------------------------------------------------
1905
1906#endif /* __cplusplus */
1907
1908// ----------------------------------------------------------------------------
1909
1910#endif /* CMSIS_PLUS_RTOS_OS_MQUEUE_H_ */
Generic clock.
Definition os-clocks.h:66
Base class for attributes.
Definition os-decls.h:577
Base class for named system objects.
Definition os-decls.h:459
const char * name(void) const
Get object name.
Definition os-decls.h:774
Priority ordered list of threads.
Definition os-lists.h:550
Standard allocator based on the RTOS system default memory manager.
Definition os-memory.h:544
Storage for a static message queue.
Definition os-mqueue.h:236
T prios[(msgs *sizeof(priority_t)+sizeof(T) - 1)/sizeof(T)]
Definition os-mqueue.h:240
T queue[(msgs *msg_size_bytes+sizeof(T) - 1)/sizeof(T)]
Definition os-mqueue.h:238
T links[((2 *msgs) *sizeof(index_t)+sizeof(T) - 1)/sizeof(T)]
Definition os-mqueue.h:239
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:1268
void * mq_queue_address
Address of the user defined storage for the message queue.
Definition os-mqueue.h:199
std::size_t mq_queue_size_bytes
Size of the user defined storage for the message queue.
Definition os-mqueue.h:204
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:749
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:1378
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:1414
virtual ~message_queue_allocated() override
Destruct the message queue.
Definition os-mqueue.h:1470
Allocator allocator_type
Standard allocator type definition.
Definition os-mqueue.h:755
Template of a POSIX compliant message queue with message type and local storage.
Definition os-mqueue.h:1041
T value_type
Local type of message.
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:1810
virtual ~message_queue_inclusive() override
Destruct the typed message queue object instance.
Definition os-mqueue.h:1796
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:1826
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:1842
message_queue_inclusive(const attributes &attr=initializer)
Construct a typed message queue object instance.
Definition os-mqueue.h:1729
static const std::size_t msgs
Local constant based on template definition.
Definition os-mqueue.h:1052
result_t receive(value_type *msg, priority_t *mprio=nullptr)
Receive a typed message from the queue.
Definition os-mqueue.h:1859
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:1891
result_t try_receive(value_type *msg, priority_t *mprio=nullptr)
Try to receive a typed message from the queue.
Definition os-mqueue.h:1875
Template of a POSIX compliant message queue with message type and allocator.
Definition os-mqueue.h:830
T value_type
Standard allocator type definition.
Definition os-mqueue.h:836
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:1601
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:1617
Allocator allocator_type
Standard allocator type definition.
Definition os-mqueue.h:841
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:1667
result_t receive(value_type *msg, message_queue::priority_t *mprio=nullptr)
Receive a typed message from the queue.
Definition os-mqueue.h:1651
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:1683
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:1520
virtual ~message_queue_typed() override
Destruct the typed message queue object instance.
Definition os-mqueue.h:1587
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:1633
POSIX compliant message queue, using the default RTOS allocator.
Definition os-mqueue.h:70
bool empty(void) const
Check if the queue is empty.
Definition os-mqueue.h:1331
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:1307
std::size_t msg_size(void) const
Get message size.
Definition os-mqueue.h:1319
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:252
bool full(void) const
Check if the queue is full.
Definition os-mqueue.h:1343
std::size_t length(void) const
Get queue length.
Definition os-mqueue.h:1295
bool operator==(const message_queue &rhs) const
Compare memory queues.
Definition os-mqueue.h:1283
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:74
port::clock::duration_t duration_t
Type of variables holding clock durations.
Definition os-clocks.h:83
static constexpr msg_size_t max_msg_size
Maximum message size.
Definition os-mqueue.h:105
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:127
message_queue::size_t index_t
Type of list index storage.
Definition os-mqueue.h:111
static constexpr priority_t default_priority
Default message priority.
Definition os-mqueue.h:135
static const attributes initializer
Default message queue initialiser.
Definition os-mqueue.h:218
uint8_t size_t
Type of a queue size storage.
Definition os-mqueue.h:86
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:99
static constexpr index_t no_index
Index value to represent an illegal index.
Definition os-mqueue.h:117
static constexpr message_queue::size_t max_size
Maximum queue size.
Definition os-mqueue.h:93
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:110
System namespace.