12 #ifndef INCLUDE_DISTORTOS_FIFOQUEUE_HPP_ 13 #define INCLUDE_DISTORTOS_FIFOQUEUE_HPP_ 25 #if __GNUC_PREREQ(5, 1) != 1 27 #error "GCC 5.1 is the minimum version supported by distortos" 49 using Storage =
typename std::aligned_storage<
sizeof(T),
alignof(T)>::type;
53 std::unique_ptr<Storage[], internal::FifoQueueBase::StorageUniquePointer::deleter_type>;
67 fifoQueueBase_{{storageUniquePointer.release(), storageUniquePointer.get_deleter()},
sizeof(T), maxElements}
96 template<
typename... Args>
100 return emplaceInternal(semaphoreWaitFunctor, std::forward<Args>(args)...);
165 return pushInternal(semaphoreWaitFunctor, std::move(value));
182 template<
typename... Args>
186 return emplaceInternal(semaphoreTryWaitFunctor, std::forward<Args>(args)...);
206 template<
typename... Args>
210 return emplaceInternal(semaphoreTryWaitForFunctor, std::forward<Args>(args)...);
234 template<
typename Rep,
typename Period,
typename... Args>
235 int tryEmplaceFor(
const std::chrono::duration<Rep, Period> duration, Args&&... args)
237 return tryEmplaceFor(std::chrono::duration_cast<TickClock::duration>(duration), std::forward<Args>(args)...);
257 template<
typename... Args>
261 return emplaceInternal(semaphoreTryWaitUntilFunctor, std::forward<Args>(args)...);
284 template<
typename Duration,
typename... Args>
285 int tryEmplaceUntil(
const std::chrono::time_point<TickClock, Duration> timePoint, Args&&... args)
287 return tryEmplaceUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint),
288 std::forward<Args>(args)...);
305 return popInternal(semaphoreTryWaitFunctor, value);
325 return popInternal(semaphoreTryWaitForFunctor, value);
347 template<
typename Rep,
typename Period>
348 int tryPopFor(
const std::chrono::duration<Rep, Period> duration, T& value)
350 return tryPopFor(std::chrono::duration_cast<TickClock::duration>(duration), value);
370 return popInternal(semaphoreTryWaitUntilFunctor, value);
391 template<
typename Duration>
392 int tryPopUntil(
const std::chrono::time_point<TickClock, Duration> timePoint, T& value)
394 return tryPopUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint), value);
427 return pushInternal(semaphoreTryWaitFunctor, std::move(value));
467 template<
typename Rep,
typename Period>
468 int tryPushFor(
const std::chrono::duration<Rep, Period> duration,
const T& value)
470 return tryPushFor(std::chrono::duration_cast<TickClock::duration>(duration), value);
490 return pushInternal(semaphoreTryWaitForFunctor, std::move(value));
512 template<
typename Rep,
typename Period>
513 int tryPushFor(
const std::chrono::duration<Rep, Period> duration, T&& value)
515 return tryPushFor(std::chrono::duration_cast<TickClock::duration>(duration), std::move(value));
534 return pushInternal(semaphoreTryWaitUntilFunctor, value);
554 template<
typename Duration>
555 int tryPushUntil(
const std::chrono::time_point<TickClock, Duration> timePoint,
const T& value)
557 return tryPushUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint), value);
577 return pushInternal(semaphoreTryWaitUntilFunctor, std::move(value));
598 template<
typename Duration>
599 int tryPushUntil(
const std::chrono::time_point<TickClock, Duration> timePoint, T&& value)
601 return tryPushUntil(std::chrono::time_point_cast<TickClock::duration>(timePoint), std::move(value));
623 template<
typename... Args>
681 while (tryPop(value) == 0);
685 template<
typename... Args>
689 [&args...](
void*
const storage)
691 new (storage) T{std::forward<Args>(args)...};
693 return fifoQueueBase_.push(waitSemaphoreFunctor, emplaceFunctor);
700 return fifoQueueBase_.pop(waitSemaphoreFunctor, swapPopQueueFunctor);
707 return fifoQueueBase_.push(waitSemaphoreFunctor, copyConstructQueueFunctor);
714 return fifoQueueBase_.push(waitSemaphoreFunctor, moveConstructQueueFunctor);
719 #endif // INCLUDE_DISTORTOS_FIFOQUEUE_HPP_ constexpr BoundQueueFunctor< F > makeBoundQueueFunctor(F &&boundFunctor)
Helper factory function to make BoundQueueFunctor object with deduced template arguments.
Definition: BoundQueueFunctor.hpp:79
int tryEmplaceUntil(const TickClock::time_point timePoint, Args &&... args)
Tries to emplace the element in the queue until a given time point.
Definition: FifoQueue.hpp:258
size_t getCapacity() const
Definition: FifoQueue.hpp:107
int tryEmplaceUntil(const std::chrono::time_point< TickClock, Duration > timePoint, Args &&... args)
Tries to emplace the element in the queue until a given time point.
Definition: FifoQueue.hpp:285
int tryPopUntil(const TickClock::time_point timePoint, T &value)
Tries to pop the oldest (first) element from the queue until a given time point.
Definition: FifoQueue.hpp:367
SemaphoreTryWaitFunctor class header.
int tryPush(T &&value)
Tries to push the element to the queue.
Definition: FifoQueue.hpp:424
int tryPush(const T &value)
Tries to push the element to the queue.
Definition: FifoQueue.hpp:407
int tryPushFor(const std::chrono::duration< Rep, Period > duration, T &&value)
Tries to push the element to the queue for a given duration of time.
Definition: FifoQueue.hpp:513
SemaphoreTryWaitFunctor class is a SemaphoreFunctor which calls Semaphore::tryWait()
Definition: SemaphoreTryWaitFunctor.hpp:24
std::unique_ptr< Storage[], internal::FifoQueueBase::StorageUniquePointer::deleter_type > StorageUniquePointer
unique_ptr (with deleter) to Storage[]
Definition: FifoQueue.hpp:53
int tryPushFor(const std::chrono::duration< Rep, Period > duration, const T &value)
Tries to push the element to the queue for a given duration of time.
Definition: FifoQueue.hpp:468
FifoQueue(StorageUniquePointer &&storageUniquePointer, const size_t maxElements)
FifoQueue's constructor.
Definition: FifoQueue.hpp:66
int emplaceInternal(const internal::SemaphoreFunctor &waitSemaphoreFunctor, Args &&... args)
Emplaces the element in the queue.
Definition: FifoQueue.hpp:686
typename std::aligned_storage< sizeof(T), alignof(T)>::type Storage
type of uninitialized storage for data
Definition: FifoQueue.hpp:49
int pop(T &value)
Pops the oldest (first) element from the queue.
Definition: FifoQueue.hpp:125
FifoQueue class is a simple FIFO queue for thread-thread, thread-interrupt or interrupt-interrupt com...
Definition: FifoQueue.hpp:44
int emplace(Args &&... args)
Emplaces the element in the queue.
Definition: FifoQueue.hpp:97
std::chrono::time_point< TickClock > time_point
basic time_point type of clock
Definition: TickClock.hpp:42
~FifoQueue()
FifoQueue's destructor.
Definition: FifoQueue.hpp:678
FifoQueueBase class header.
int tryPushUntil(const std::chrono::time_point< TickClock, Duration > timePoint, T &&value)
Tries to push the element to the queue until a given time point.
Definition: FifoQueue.hpp:599
int tryPop(T &value)
Tries to pop the oldest (first) element from the queue.
Definition: FifoQueue.hpp:302
SemaphoreTryWaitUntilFunctor class header.
Definition: SemaphoreTryWaitUntilFunctor.hpp:27
Definition: SwapPopQueueFunctor.hpp:32
CopyConstructQueueFunctor class header.
int tryPopFor(const TickClock::duration duration, T &value)
Tries to pop the oldest (first) element from the queue for a given duration of time.
Definition: FifoQueue.hpp:322
int push(T &&value)
Pushes the element to the queue.
Definition: FifoQueue.hpp:162
BoundQueueFunctor class header.
internal::FifoQueueBase fifoQueueBase_
contained internal::FifoQueueBase object which implements whole functionality
Definition: FifoQueue.hpp:674
FifoQueueBase class implements basic functionality of FifoQueue template class.
Definition: FifoQueueBase.hpp:29
Top-level namespace of distortos project.
Definition: buttons.hpp:33
Definition: CopyConstructQueueFunctor.hpp:30
SemaphoreFunctor is a type-erased interface for functors which execute some action on semaphore (wait...
Definition: SemaphoreFunctor.hpp:34
int pushInternal(const internal::SemaphoreFunctor &waitSemaphoreFunctor, const T &value)
Pushes the element to the queue.
Definition: FifoQueue.hpp:704
SemaphoreTryWaitForFunctor class header.
int tryPopUntil(const std::chrono::time_point< TickClock, Duration > timePoint, T &value)
Tries to pop the oldest (first) element from the queue until a given time point.
Definition: FifoQueue.hpp:392
std::chrono::duration< rep, period > duration
basic duration type of clock
Definition: TickClock.hpp:39
SwapPopQueueFunctor class header.
T ValueType
type of data in queue
Definition: FifoQueue.hpp:56
size_t getCapacity() const
Definition: FifoQueueBase.hpp:57
int tryPopFor(const std::chrono::duration< Rep, Period > duration, T &value)
Tries to pop the oldest (first) element from the queue for a given duration of time.
Definition: FifoQueue.hpp:348
int popInternal(const internal::SemaphoreFunctor &waitSemaphoreFunctor, T &value)
Pops the oldest (first) element from the queue.
Definition: FifoQueue.hpp:697
int tryEmplaceFor(const std::chrono::duration< Rep, Period > duration, Args &&... args)
Tries to emplace the element in the queue for a given duration of time.
Definition: FifoQueue.hpp:235
int tryPushUntil(const TickClock::time_point timePoint, const T &value)
Tries to push the element to the queue until a given time point.
Definition: FifoQueue.hpp:531
int push(const T &value)
Pushes the element to the queue.
Definition: FifoQueue.hpp:143
SemaphoreWaitFunctor class header.
int tryPushFor(const TickClock::duration duration, T &&value)
Tries to push the element to the queue for a given duration of time.
Definition: FifoQueue.hpp:487
int tryPushUntil(const std::chrono::time_point< TickClock, Duration > timePoint, const T &value)
Tries to push the element to the queue until a given time point.
Definition: FifoQueue.hpp:555
int tryEmplace(Args &&... args)
Tries to emplace the element in the queue.
Definition: FifoQueue.hpp:183
int tryPushFor(const TickClock::duration duration, const T &value)
Tries to push the element to the queue for a given duration of time.
Definition: FifoQueue.hpp:443
MoveConstructQueueFunctor class header.
SemaphoreTryWaitForFunctor class is a SemaphoreFunctor which calls Semaphore::tryWaitFor() with bound...
Definition: SemaphoreTryWaitForFunctor.hpp:26
int tryPushUntil(const TickClock::time_point timePoint, T &&value)
Tries to push the element to the queue until a given time point.
Definition: FifoQueue.hpp:574
SemaphoreWaitFunctor class is a SemaphoreFunctor which calls Semaphore::wait()
Definition: SemaphoreWaitFunctor.hpp:24
int tryEmplaceFor(const TickClock::duration duration, Args &&... args)
Tries to emplace the element in the queue for a given duration of time.
Definition: FifoQueue.hpp:207
Definition: MoveConstructQueueFunctor.hpp:32