µOS++ IIIe Reference  v6.3.15
“Perfekt ist nicht gut genug”
The third edition of µOS++, a POSIX inspired open source system, written in C++.
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 
37 
38 #include <cmsis-plus/diag/trace.h>
39 
40 // ----------------------------------------------------------------------------
41 
42 namespace os
43 {
44  namespace rtos
45  {
46 
47  // ========================================================================
48 
49 #pragma GCC diagnostic push
50 #pragma GCC diagnostic ignored "-Wpadded"
51 
59  {
60  public:
61 
62  // ======================================================================
63 
72 #if defined(OS_BOOL_RTOS_MESSAGE_QUEUE_SIZE_16BITS)
73  using size_t = uint16_t;
74 #else
75  using size_t = uint8_t;
76 #endif
77 
82  static constexpr message_queue::size_t max_size = 0xFF;
83 
88  using msg_size_t = uint16_t;
89 
94  static constexpr msg_size_t max_msg_size = 0xFFFF;
95 
101 
106  static constexpr index_t no_index = max_size;
107 
116  using priority_t = uint8_t;
117 
124  static constexpr priority_t default_priority = 0;
125 
133  static constexpr priority_t max_priority = 0xFF;
134 
135  // ======================================================================
136 
143  {
144  public:
145 
156  constexpr
157  attributes ();
158 
159  // The rule of five.
160  attributes (const attributes&) = default;
161  attributes (attributes&&) = default;
162  attributes&
163  operator= (const attributes&) = default;
164  attributes&
165  operator= (attributes&&) = default;
166 
170  ~attributes () = default;
171 
176  public:
177 
183  // Public members; no accessors and mutators required.
184  // Warning: must match the type & order of the C file header.
188  void* mq_queue_address = nullptr;
189 
193  std::size_t mq_queue_size_bytes = 0;
194 
195  // Add more attributes here.
196 
201  }; /* class attributes */
202 
207  static const attributes initializer;
208 
214 
223  template<typename T, std::size_t msgs, std::size_t msg_size_bytes>
224  class arena
225  {
226  public:
227  T queue[(msgs * msg_size_bytes + sizeof(T) - 1) / sizeof(T)];
228  T links[((2 * msgs) * sizeof(index_t) + sizeof(T) - 1) / sizeof(T)];
229  T prios[(msgs * sizeof(priority_t) + sizeof(T) - 1) / sizeof(T)];
230  };
231 
239  template<typename T>
240  constexpr std::size_t
241  compute_allocated_size_bytes (std::size_t msgs,
242  std::size_t msg_size_bytes)
243  {
244  // Align each message
245  return (msgs * ((msg_size_bytes + (sizeof(T) - 1)) & ~(sizeof(T) - 1)))
246  // Align the indices array
247  + ((2 * msgs * sizeof(index_t) + (sizeof(T) - 1))
248  & ~(sizeof(T) - 1))
249  // Align the priority array
250  + ((msgs * sizeof(priority_t) + (sizeof(T) - 1))
251  & ~(sizeof(T) - 1));
252  }
253 
254  // ======================================================================
255 
269  message_queue (std::size_t msgs, std::size_t msg_size_bytes,
270  const attributes& attr = initializer,
272 
282  message_queue (const char* name, std::size_t msgs,
283  std::size_t msg_size_bytes, const attributes& attr =
284  initializer,
286 
287  protected:
288 
293  // Internal constructors, used from templates.
294  message_queue ();
295  message_queue (const char* name);
296 
301  public:
302 
307  // The rule of five.
308  message_queue (const message_queue&) = delete;
309  message_queue (message_queue&&) = delete;
311  operator= (const message_queue&) = delete;
313  operator= (message_queue&&) = delete;
314 
322  virtual
323  ~message_queue ();
324 
339  bool
340  operator== (const message_queue& rhs) const;
341 
346  public:
347 
368  result_t
369  send (const void* msg, std::size_t nbytes, priority_t mprio =
371 
386  result_t
387  try_send (const void* msg, std::size_t nbytes, priority_t mprio =
389 
408  result_t
409  timed_send (const void* msg, std::size_t nbytes,
410  clock::duration_t timeout,
411  priority_t mprio = default_priority);
412 
431  result_t
432  receive (void* msg, std::size_t nbytes, priority_t* mprio = nullptr);
433 
451  result_t
452  try_receive (void* msg, std::size_t nbytes, priority_t* mprio = nullptr);
453 
475  result_t
476  timed_receive (void* msg, std::size_t nbytes, clock::duration_t timeout,
477  priority_t* mprio = nullptr);
478 
479  // TODO: check if some kind of peek() is useful.
480 
487  std::size_t
488  capacity (void) const;
489 
496  std::size_t
497  length (void) const;
498 
505  std::size_t
506  msg_size (void) const;
507 
515  bool
516  empty (void) const;
517 
525  bool
526  full (void) const;
527 
535  result_t
536  reset (void);
537 
542  protected:
543 
563  void
564  internal_construct_ (std::size_t msgs, std::size_t msg_size_bytes,
565  const attributes& attr, void* queue_address,
566  std::size_t queue_size_bytes);
567 
575  void
576  internal_init_ (void);
577 
578 #if !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE)
579 
589  bool
590  internal_try_send_ (const void* msg, std::size_t nbytes,
591  priority_t mprio);
592 
603  bool
604  internal_try_receive_ (void* msg, std::size_t nbytes, priority_t* mprio);
605 
606 #endif /* !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE) */
607 
616  protected:
617 
627  // Keep these in sync with the structure declarations in os-c-decl.h.
628 #if !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE)
629 
636  internal::waiting_threads_list receive_list_;
640  clock* clock_ = nullptr;
641 
642  // To save space, the double linked list is built
643  // using short indexes, not pointers.
647  volatile index_t* prev_array_ = nullptr;
651  volatile index_t* next_array_ = nullptr;
655  volatile priority_t* prio_array_ = nullptr;
656 
666  void* volatile first_free_ = nullptr;
667 #endif /* !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE) */
668 
673  void* queue_addr_ = nullptr;
678  void* allocated_queue_addr_ = nullptr;
682  const void* allocator_ = nullptr;
683 
684 #if defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE)
685  friend class port::message_queue;
686  os_mqueue_port_data_t port_;
687 #endif
688 
693  std::size_t queue_size_bytes_ = 0;
697  std::size_t allocated_queue_size_elements_ = 0;
698 
702  message_queue::msg_size_t msg_size_bytes_ = 0;
706  message_queue::size_t msgs_ = 0;
710  message_queue::size_t count_ = 0;
711 
712 #if !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE)
713 
716  index_t head_ = 0;
717 #endif /* !defined(OS_USE_RTOS_PORT_MESSAGE_QUEUE) */
718 
727  };
728 
729  // ========================================================================
730 
736  template<typename Allocator = memory::allocator<void*>>
738  {
739  public:
740 
744  using allocator_type = Allocator;
745 
759  message_queue_allocated (std::size_t msgs, std::size_t msg_size_bytes,
760  const attributes& attr = initializer,
761  const allocator_type& allocator =
762  allocator_type ());
763 
773  message_queue_allocated (const char* name, std::size_t msgs,
774  std::size_t msg_size_bytes,
775  const attributes& attr = initializer,
776  const allocator_type& allocator =
777  allocator_type ());
778 
779  public:
780 
785  // The rule of five.
789  operator= (const message_queue_allocated&) = delete;
792 
800  virtual
802 
807  };
808 
809  // ========================================================================
810 
817  template<typename T, typename Allocator = memory::allocator<void*>>
819  {
820  public:
821 
825  using value_type = T;
826 
830  using allocator_type = Allocator;
831 
844  message_queue_typed (std::size_t msgs,
845  const message_queue::attributes& attr =
847  const allocator_type& allocator =
848  allocator_type ());
849 
858  message_queue_typed (const char* name, std::size_t msgs,
859  const message_queue::attributes& attr =
861  const allocator_type& allocator =
862  allocator_type ());
863 
868  // The rule of five.
869  message_queue_typed (const message_queue_typed&) = delete;
872  operator= (const message_queue_typed&) = delete;
874  operator= (message_queue_typed&&) = delete;
875 
883  virtual
885 
890  public:
891 
910  result_t
911  send (const value_type* msg, message_queue::priority_t mprio =
913 
927  result_t
928  try_send (const value_type* msg, message_queue::priority_t mprio =
930 
947  result_t
948  timed_send (const value_type* msg, clock::duration_t timeout,
951 
968  result_t
969  receive (value_type* msg, message_queue::priority_t* mprio = nullptr);
970 
987  result_t
988  try_receive (value_type* msg,
989  message_queue::priority_t* mprio = nullptr);
990 
1010  result_t
1012  message_queue::priority_t* mprio = nullptr);
1013 
1018  };
1019 
1020  // ========================================================================
1021 
1028  template<typename T, std::size_t N>
1030  {
1031  public:
1032 
1036  using value_type = T;
1037 
1041  static const std::size_t msgs = N;
1042 
1053 
1059  message_queue_inclusive (const char* name, const attributes& attr =
1060  initializer);
1061 
1066  // The rule of five.
1070  operator= (const message_queue_inclusive&) = delete;
1072  operator= (message_queue_inclusive&&) = delete;
1073 
1081  virtual
1083 
1088  public:
1089 
1108  result_t
1109  send (const value_type* msg, priority_t mprio = default_priority);
1110 
1124  result_t
1125  try_send (const value_type* msg, priority_t mprio = default_priority);
1126 
1143  result_t
1144  timed_send (const value_type* msg, clock::duration_t timeout,
1145  priority_t mprio = default_priority);
1146 
1163  result_t
1164  receive (value_type* msg, priority_t* mprio = nullptr);
1165 
1182  result_t
1183  try_receive (value_type* msg, priority_t* mprio = nullptr);
1184 
1204  result_t
1206  priority_t* mprio = nullptr);
1207 
1212  protected:
1213 
1233 
1242  };
1243 
1244 #pragma GCC diagnostic pop
1245 
1246  }
1247 /* namespace rtos */
1248 } /* namespace os */
1249 
1250 // ===== Inline & template implementations ====================================
1251 
1252 namespace os
1253 {
1254  namespace rtos
1255  {
1256  constexpr
1258  {
1259  ;
1260  }
1261 
1262  // ========================================================================
1263 
1271  inline bool
1273  {
1274  return this == &rhs;
1275  }
1276 
1284  inline std::size_t
1286  {
1287  return count_;
1288  }
1289 
1297  inline std::size_t
1299  {
1300  return msgs_;
1301  }
1302 
1310  inline std::size_t
1312  {
1313  return msg_size_bytes_;
1314  }
1315 
1323  inline bool
1325  {
1326  return (length () == 0);
1327  }
1328 
1336  inline bool
1337  message_queue::full (void) const
1338  {
1339  return (length () == capacity ());
1340  }
1341 
1342  // ========================================================================
1343 
1370  template<typename Allocator>
1371  inline
1373  std::size_t msgs, std::size_t msg_size_bytes, const attributes& attr,
1374  const allocator_type& allocator) :
1376  { nullptr, msgs, msg_size_bytes, attr, allocator }
1377  {
1378  ;
1379  }
1380 
1407  template<typename Allocator>
1409  const char* name, std::size_t msgs, std::size_t msg_size_bytes,
1410  const attributes& attr, const allocator_type& allocator) :
1412  { name }
1413  {
1414 #if defined(OS_TRACE_RTOS_MQUEUE)
1415  trace::printf ("%s() @%p %s %d %d\n", __func__, this, this->name (),
1416  msgs, msg_size_bytes);
1417 #endif
1418 
1419  if (attr.mq_queue_address != nullptr)
1420  {
1421  // Do not use any allocator at all.
1422  internal_construct_ (msgs, msg_size_bytes, attr, nullptr, 0);
1423  }
1424  else
1425  {
1426  allocator_ = &allocator;
1427 
1428  // If no user storage was provided via attributes,
1429  // allocate it dynamically via the allocator.
1430  allocated_queue_size_elements_ = (compute_allocated_size_bytes<
1431  typename allocator_type::value_type> (msgs, msg_size_bytes)
1432  + sizeof(typename allocator_type::value_type) - 1)
1433  / sizeof(typename allocator_type::value_type);
1434 
1435  allocated_queue_addr_ =
1436  const_cast<allocator_type&> (allocator).allocate (
1437  allocated_queue_size_elements_);
1438 
1439  internal_construct_ (
1440  msgs,
1441  msg_size_bytes,
1442  attr,
1443  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_))->deallocate (
1474  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>
1513  inline
1515  std::size_t msgs, const message_queue::attributes& attr,
1516  const allocator_type& allocator) :
1518  { msgs, sizeof(value_type), attr, allocator }
1519  {
1520  ;
1521  }
1522 
1552  template<typename T, typename Allocator>
1553  inline
1555  const char* name, std::size_t msgs,
1556  const message_queue::attributes& attr,
1557  const allocator_type& allocator) :
1559  { name, msgs, sizeof(value_type), attr, allocator }
1560  {
1561  ;
1562  }
1563 
1580  template<typename T, typename Allocator>
1582  {
1583  ;
1584  }
1585 
1593  template<typename T, typename Allocator>
1594  inline result_t
1597  {
1599  reinterpret_cast<const char*> (msg), sizeof(value_type), mprio);
1600  }
1601 
1609  template<typename T, typename Allocator>
1610  inline result_t
1612  const value_type* msg, message_queue::priority_t mprio)
1613  {
1615  reinterpret_cast<const char*> (msg), sizeof(value_type), mprio);
1616  }
1617 
1625  template<typename T, typename Allocator>
1626  inline result_t
1628  const value_type* msg, clock::duration_t timeout,
1630  {
1632  reinterpret_cast<const char*> (msg), sizeof(value_type), timeout,
1633  mprio);
1634  }
1635 
1643  template<typename T, typename Allocator>
1644  inline result_t
1647  {
1649  reinterpret_cast<char*> (msg), sizeof(value_type), mprio);
1650  }
1651 
1659  template<typename T, typename Allocator>
1660  inline result_t
1663  {
1665  reinterpret_cast<char*> (msg), sizeof(value_type), mprio);
1666  }
1667 
1675  template<typename T, typename Allocator>
1676  inline result_t
1678  value_type* msg, clock::duration_t timeout,
1680  {
1682  reinterpret_cast<char*> (msg), sizeof(value_type), timeout, mprio);
1683  }
1684 
1685  // ========================================================================
1686 
1721  template<typename T, std::size_t N>
1722  inline
1724  const attributes& attr) :
1726  { nullptr, attr }
1727  {
1728  ;
1729  }
1730 
1765  template<typename T, std::size_t N>
1767  const char* name, const attributes& attr) :
1768  message_queue (name)
1769  {
1770  static_assert(sizeof(T) >= sizeof(void*), "Messages of message_queue need to have at least the 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  }
1794 
1802  template<typename T, std::size_t N>
1803  inline result_t
1805  priority_t mprio)
1806  {
1807  return message_queue::send (reinterpret_cast<const char*> (msg),
1808  sizeof(value_type), mprio);
1809  }
1810 
1818  template<typename T, std::size_t N>
1819  inline result_t
1821  priority_t mprio)
1822  {
1823  return message_queue::try_send (reinterpret_cast<const char*> (msg),
1824  sizeof(value_type), mprio);
1825  }
1826 
1834  template<typename T, std::size_t N>
1835  inline result_t
1837  clock::duration_t timeout,
1838  priority_t mprio)
1839  {
1840  return message_queue::timed_send (reinterpret_cast<const char*> (msg),
1841  sizeof(value_type), timeout, mprio);
1842  }
1843 
1851  template<typename T, std::size_t N>
1852  inline result_t
1854  priority_t* mprio)
1855  {
1856  return message_queue::receive (reinterpret_cast<char*> (msg),
1857  sizeof(value_type), mprio);
1858  }
1859 
1867  template<typename T, std::size_t N>
1868  inline result_t
1870  priority_t* mprio)
1871  {
1872  return message_queue::try_receive (reinterpret_cast<char*> (msg),
1873  sizeof(value_type), mprio);
1874  }
1875 
1883  template<typename T, std::size_t N>
1884  inline result_t
1886  clock::duration_t timeout,
1887  priority_t* mprio)
1888  {
1889  return message_queue::timed_receive (reinterpret_cast<char*> (msg),
1890  sizeof(value_type), timeout, mprio);
1891  }
1892 
1893  } /* namespace rtos */
1894 } /* namespace os */
1895 
1896 // ----------------------------------------------------------------------------
1897 
1898 #endif /* __cplusplus */
1899 
1900 #endif /* CMSIS_PLUS_RTOS_OS_MQUEUE_H_ */
message_queue::size_t index_t
Type of list index storage.
Definition: os-mqueue.h:100
virtual ~message_queue()
Destruct the message queue object instance.
Definition: os-mqueue.cpp:473
attributes & operator=(const attributes &)=default
message_queue_inclusive(const attributes &attr=initializer)
Construct a typed message queue object instance.
Definition: os-mqueue.h:1723
result_t reset(void)
Reset the message queue.
Definition: os-mqueue.cpp:1525
result_t try_receive(value_type *msg, priority_t *mprio=nullptr)
Try to receive a typed message from the queue.
Definition: os-mqueue.h:1869
result_t receive(value_type *msg, priority_t *mprio=nullptr)
Receive a typed message from the queue.
Definition: os-mqueue.h:1853
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:1820
void deallocate(value_type *addr, std::size_t elements) noexcept
Deallocate the number of memory blocks of type value_type.
Definition: os-memory.h:1500
result_t try_send(const void *msg, std::size_t nbytes, priority_t mprio=default_priority)
Try to send a message to the queue.
Definition: os-mqueue.cpp:981
Priority ordered list of threads.
Definition: os-lists.h:536
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.
Definition: os-mqueue.cpp:1065
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:1836
result_t receive(void *msg, std::size_t nbytes, priority_t *mprio=nullptr)
Receive a message from the queue.
Definition: os-mqueue.cpp:1202
uint16_t msg_size_t
Type of message size storage.
Definition: os-mqueue.h:88
Template of a POSIX compliant message queue with message type and allocator.
Definition: os-mqueue.h:818
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:1661
static constexpr message_queue::size_t max_size
Maximum queue size.
Definition: os-mqueue.h:82
Base class for attributes.
Definition: os-decls.h:562
System namespace.
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:1372
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:241
result_t try_receive(void *msg, std::size_t nbytes, priority_t *mprio=nullptr)
Try to receive a message from the queue.
Definition: os-mqueue.cpp:1314
T value_type
Local type of message.
Definition: os-mqueue.h:1036
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:1677
bool full(void) const
Check if the queue is full.
Definition: os-mqueue.h:1337
bool empty(void) const
Check if the queue is empty.
Definition: os-mqueue.h:1324
uint8_t size_t
Type of a queue size storage.
Definition: os-mqueue.h:75
static constexpr priority_t max_priority
Maximum message priority.
Definition: os-mqueue.h:133
const char * name(void) const
Get object name.
Definition: os-decls.h:760
Base class for named system objects.
Definition: os-decls.h:444
uint8_t priority_t
Type of message priority storage.
Definition: os-mqueue.h:116
virtual ~message_queue_inclusive()
Destruct the typed message queue object instance.
Definition: os-mqueue.h:1790
Template of a POSIX compliant message queue with message type and local storage.
Definition: os-mqueue.h:1029
port::clock::duration_t duration_t
Type of variables holding clock durations.
Definition: os-clocks.h:72
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:1611
std::size_t mq_queue_size_bytes
Size of the user defined storage for the message queue.
Definition: os-mqueue.h:193
virtual ~message_queue_allocated()
Destruct the message queue.
Definition: os-mqueue.h:1464
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition: trace.cpp:74
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:1595
T value_type
Standard allocator type definition.
Definition: os-mqueue.h:825
result_t send(const void *msg, std::size_t nbytes, priority_t mprio=default_priority)
Send a message to the queue.
Definition: os-mqueue.cpp:870
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.
Definition: os-mqueue.cpp:1412
static constexpr index_t no_index
Index value to represent an illegal index.
Definition: os-mqueue.h:106
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:1514
static const attributes initializer
Default message queue initialiser.
Definition: os-mqueue.h:207
T value_type
Type of elements to be allocated.
Definition: os-memory.h:539
static constexpr priority_t default_priority
Default message priority.
Definition: os-mqueue.h:124
bool operator==(const message_queue &rhs) const
Compare memory queues.
Definition: os-mqueue.h:1272
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:1885
result_t send(const value_type *msg, priority_t mprio=default_priority)
Send a typed message to the queue.
Definition: os-mqueue.h:1804
static constexpr msg_size_t max_msg_size
Maximum message size.
Definition: os-mqueue.h:94
std::size_t msg_size(void) const
Get message size.
Definition: os-mqueue.h:1311
constexpr attributes()
Construct a message queue attributes object instance.
Definition: os-mqueue.h:1257
std::size_t length(void) const
Get queue length.
Definition: os-mqueue.h:1285
virtual ~message_queue_typed()
Destruct the typed message queue object instance.
Definition: os-mqueue.h:1581
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:1627
Generic clock.
Definition: os-clocks.h:54
Storage for a static message queue.
Definition: os-mqueue.h:224
result_t receive(value_type *msg, message_queue::priority_t *mprio=nullptr)
Receive a typed message from the queue.
Definition: os-mqueue.h:1645
~attributes()=default
Destruct the message queue attributes object instance.
uint32_t result_t
Type of values returned by RTOS functions.
Definition: os-decls.h:96
void * mq_queue_address
Address of the user defined storage for the message queue.
Definition: os-mqueue.h:188
Message queue attributes.
Definition: os-mqueue.h:142
message_queue(std::size_t msgs, std::size_t msg_size_bytes, const attributes &attr=initializer, const allocator_type &allocator=allocator_type())
Construct a message queue object instance.
Definition: os-mqueue.cpp:382
Template of a POSIX compliant message queue with allocator.
Definition: os-mqueue.h:737
std::size_t capacity(void) const
Get queue capacity.
Definition: os-mqueue.h:1298
allocator_stateless_default_resource< T > allocator
Type of allocator used by the system objects. Must be stateless.
Definition: os-types.h:57
Standard allocator based on the RTOS system default memory manager.
Definition: os-decls.h:82
POSIX compliant message queue, using the default RTOS allocator.
Definition: os-mqueue.h:58