distortos  v0.4.0
object-oriented C++ RTOS for microcontrollers
FifoQueueBase.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_INTERNAL_SYNCHRONIZATION_FIFOQUEUEBASE_HPP_
13 #define INCLUDE_DISTORTOS_INTERNAL_SYNCHRONIZATION_FIFOQUEUEBASE_HPP_
14 
15 #include "distortos/Semaphore.hpp"
16 
19 
20 #include <memory>
21 
22 namespace distortos
23 {
24 
25 namespace internal
26 {
27 
30 {
31 public:
32 
34  using StorageUniquePointer = std::unique_ptr<void, void(&)(void*)>;
35 
45  FifoQueueBase(StorageUniquePointer&& storageUniquePointer, size_t elementSize, size_t maxElements);
46 
52 
57  size_t getElementSize() const
58  {
59  return elementSize_;
60  }
61 
74  int pop(const SemaphoreFunctor& waitSemaphoreFunctor, const QueueFunctor& functor)
75  {
76  return popPush(waitSemaphoreFunctor, functor, popSemaphore_, pushSemaphore_, readPosition_);
77  }
78 
91  int push(const SemaphoreFunctor& waitSemaphoreFunctor, const QueueFunctor& functor)
92  {
93  return popPush(waitSemaphoreFunctor, functor, pushSemaphore_, popSemaphore_, writePosition_);
94  }
95 
96 private:
97 
116  int popPush(const SemaphoreFunctor& waitSemaphoreFunctor, const QueueFunctor& functor, Semaphore& waitSemaphore,
117  Semaphore& postSemaphore, void*& storage);
118 
121 
124 
127 
129  const void* const storageEnd_;
130 
133 
136 
138  const size_t elementSize_;
139 };
140 
141 } // namespace internal
142 
143 } // namespace distortos
144 
145 #endif // INCLUDE_DISTORTOS_INTERNAL_SYNCHRONIZATION_FIFOQUEUEBASE_HPP_
void * writePosition_
pointer to first free slot available for writing
Definition: FifoQueueBase.hpp:135
Semaphore is the basic synchronization primitive.
Definition: Semaphore.hpp:30
FifoQueueBase(StorageUniquePointer &&storageUniquePointer, size_t elementSize, size_t maxElements)
FifoQueueBase&#39;s constructor.
Definition: FifoQueueBase.cpp:26
const StorageUniquePointer storageUniquePointer_
storage for queue elements
Definition: FifoQueueBase.hpp:126
Semaphore popSemaphore_
semaphore guarding access to "pop" functions - its value is equal to the number of available elements...
Definition: FifoQueueBase.hpp:120
Semaphore class header.
int pop(const SemaphoreFunctor &waitSemaphoreFunctor, const QueueFunctor &functor)
Implementation of pop() using type-erased functor.
Definition: FifoQueueBase.hpp:74
~FifoQueueBase()
FifoQueueBase&#39;s destructor.
Definition: FifoQueueBase.cpp:39
void * readPosition_
pointer to first element available for reading
Definition: FifoQueueBase.hpp:132
const void *const storageEnd_
pointer to past-the-last element of storage for queue elements
Definition: FifoQueueBase.hpp:129
std::unique_ptr< void, void(&)(void *)> StorageUniquePointer
unique_ptr (with deleter) to storage
Definition: FifoQueueBase.hpp:34
FifoQueueBase class implements basic functionality of FifoQueue template class.
Definition: FifoQueueBase.hpp:29
Top-level namespace of distortos project.
QueueFunctor class header.
size_t getElementSize() const
Definition: FifoQueueBase.hpp:57
SemaphoreFunctor is a type-erased interface for functors which execute some action on semaphore (wait...
Definition: SemaphoreFunctor.hpp:34
int popPush(const SemaphoreFunctor &waitSemaphoreFunctor, const QueueFunctor &functor, Semaphore &waitSemaphore, Semaphore &postSemaphore, void *&storage)
Implementation of pop() and push() using type-erased functor.
Definition: FifoQueueBase.cpp:48
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.
int push(const SemaphoreFunctor &waitSemaphoreFunctor, const QueueFunctor &functor)
Implementation of push() using type-erased functor.
Definition: FifoQueueBase.hpp:91
Semaphore pushSemaphore_
semaphore guarding access to "push" functions - its value is equal to the number of free slots ...
Definition: FifoQueueBase.hpp:123
const size_t elementSize_
size of single queue element, bytes
Definition: FifoQueueBase.hpp:138