distortos  v0.5.0
object-oriented C++ RTOS for microcontrollers
MessageQueueBase.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_INTERNAL_SYNCHRONIZATION_MESSAGEQUEUEBASE_HPP_
13 #define INCLUDE_DISTORTOS_INTERNAL_SYNCHRONIZATION_MESSAGEQUEUEBASE_HPP_
14 
15 #include "distortos/Semaphore.hpp"
16 
19 
21 
22 #include <memory>
23 
24 namespace distortos
25 {
26 
27 namespace internal
28 {
29 
32 {
33 public:
34 
36  struct Entry
37  {
45  constexpr Entry(const uint8_t priorityy, void* const storagee) :
46  node{},
47  priority{priorityy},
48  storage{storagee}
49  {
50 
51  }
52 
55 
57  uint8_t priority;
58 
60  void* storage;
61  };
62 
64  using EntryStorage = typename std::aligned_storage<sizeof(Entry), alignof(Entry)>::type;
65 
67  using EntryStorageUniquePointer = std::unique_ptr<EntryStorage[], void(&)(EntryStorage*)>;
68 
75  template<typename T>
76  using ValueStorage = typename std::aligned_storage<sizeof(T), alignof(T)>::type;
77 
79  using ValueStorageUniquePointer = std::unique_ptr<void, void(&)(void*)>;
80 
83  {
88  constexpr DescendingPriority()
89  {
90 
91  }
92 
102  bool operator()(const Entry& left, const Entry& right) const
103  {
104  return left.priority < right.priority;
105  }
106  };
107 
110 
113 
122  class InternalFunctor : public estd::TypeErasedFunctor<void(EntryList&, FreeEntryList&)>
123  {
124 
125  };
126 
138  MessageQueueBase(EntryStorageUniquePointer&& entryStorageUniquePointer,
139  ValueStorageUniquePointer&& valueStorageUniquePointer, size_t elementSize, size_t maxElements);
140 
146 
160  int pop(const SemaphoreFunctor& waitSemaphoreFunctor, uint8_t& priority, const QueueFunctor& functor);
161 
175  int push(const SemaphoreFunctor& waitSemaphoreFunctor, uint8_t priority, const QueueFunctor& functor);
176 
177 private:
178 
195  int popPush(const SemaphoreFunctor& waitSemaphoreFunctor, const InternalFunctor& internalFunctor,
196  Semaphore& waitSemaphore, Semaphore& postSemaphore);
197 
200 
203 
206 
209 
212 
215 };
216 
217 } // namespace internal
218 
219 } // namespace distortos
220 
221 #endif // INCLUDE_DISTORTOS_INTERNAL_SYNCHRONIZATION_MESSAGEQUEUEBASE_HPP_
int pop(const SemaphoreFunctor &waitSemaphoreFunctor, uint8_t &priority, const QueueFunctor &functor)
Implementation of pop() using type-erased functor.
Definition: MessageQueueBase.cpp:157
constexpr DescendingPriority()
DescendingPriority&#39;s constructor.
Definition: MessageQueueBase.hpp:88
Semaphore is the basic synchronization primitive.
Definition: Semaphore.hpp:30
SortedIntrusiveForwardList template class header.
const EntryStorageUniquePointer entryStorageUniquePointer_
storage for queue entries
Definition: MessageQueueBase.hpp:205
Definition: TypeErasedFunctor.hpp:19
EntryList::UnsortedIntrusiveForwardList FreeEntryList
type of free entry list
Definition: MessageQueueBase.hpp:112
FreeEntryList freeEntryList_
list of "free" entries
Definition: MessageQueueBase.hpp:214
void * storage
storage for the entry
Definition: MessageQueueBase.hpp:60
int push(const SemaphoreFunctor &waitSemaphoreFunctor, uint8_t priority, const QueueFunctor &functor)
Implementation of push() using type-erased functor.
Definition: MessageQueueBase.cpp:163
MessageQueueBase class implements basic functionality of MessageQueue template class.
Definition: MessageQueueBase.hpp:31
IntrusiveForwardListNode class is the node that is needed for the object to be linked in IntrusiveFor...
Definition: IntrusiveForwardList.hpp:38
Semaphore class header.
estd::IntrusiveForwardListNode node
node for intrusive forward list
Definition: MessageQueueBase.hpp:54
IntrusiveForwardList< Entry, NodePointer, Entry > UnsortedIntrusiveForwardList
unsorted intrusive forward list used internally
Definition: SortedIntrusiveForwardList.hpp:45
constexpr Entry(const uint8_t priorityy, void *const storagee)
Entry&#39;s constructor.
Definition: MessageQueueBase.hpp:45
const ValueStorageUniquePointer valueStorageUniquePointer_
storage for queue elements
Definition: MessageQueueBase.hpp:208
EntryList entryList_
list of available entries, sorted in descending order of priority
Definition: MessageQueueBase.hpp:211
int popPush(const SemaphoreFunctor &waitSemaphoreFunctor, const InternalFunctor &internalFunctor, Semaphore &waitSemaphore, Semaphore &postSemaphore)
Implementation of pop() and push() using type-erased internal functor.
Definition: MessageQueueBase.cpp:174
MessageQueueBase(EntryStorageUniquePointer &&entryStorageUniquePointer, ValueStorageUniquePointer &&valueStorageUniquePointer, size_t elementSize, size_t maxElements)
MessageQueueBase&#39;s constructor.
Definition: MessageQueueBase.cpp:135
Top-level namespace of distortos project.
~MessageQueueBase()
MessageQueueBase&#39;s destructor.
Definition: MessageQueueBase.cpp:152
QueueFunctor class header.
typename std::aligned_storage< sizeof(T), alignof(T)>::type ValueStorage
Definition: MessageQueueBase.hpp:76
Semaphore popSemaphore_
semaphore guarding access to "pop" functions - its value is equal to the number of available elements...
Definition: MessageQueueBase.hpp:199
SemaphoreFunctor is a type-erased interface for functors which execute some action on semaphore (wait...
Definition: SemaphoreFunctor.hpp:34
std::unique_ptr< EntryStorage[], void(&)(EntryStorage *)> EntryStorageUniquePointer
unique_ptr (with deleter) to EntryStorage[]
Definition: MessageQueueBase.hpp:67
functor which gives descending priority order of elements on the list
Definition: MessageQueueBase.hpp:82
typename std::aligned_storage< sizeof(Entry), alignof(Entry)>::type EntryStorage
type of uninitialized storage for Entry
Definition: MessageQueueBase.hpp:64
Semaphore pushSemaphore_
semaphore guarding access to "push" functions - its value is equal to the number of free slots ...
Definition: MessageQueueBase.hpp:202
uint8_t priority
priority of the entry
Definition: MessageQueueBase.hpp:57
QueueFunctor is a type-erased interface for functors which execute some action on queue&#39;s storage (li...
Definition: QueueFunctor.hpp:31
SemaphoreFunctor class header.
std::unique_ptr< void, void(&)(void *)> ValueStorageUniquePointer
unique_ptr (with deleter) to storage
Definition: MessageQueueBase.hpp:79
InternalFunctor is a type-erased interface for functors which execute common code of pop() and push()...
Definition: MessageQueueBase.hpp:122
bool operator()(const Entry &left, const Entry &right) const
DescendingPriority&#39;s function call operator.
Definition: MessageQueueBase.hpp:102
entry in the MessageQueueBase
Definition: MessageQueueBase.hpp:36