34#ifndef _UTILS_QUEUE_HXX_
35#define _UTILS_QUEUE_HXX_
235 return (
head == NULL);
445 result_ =
static_cast<T *
>(item);
451 DIE(
"Unexpected call to Run() in BlockingWait");
465template <
unsigned ITEMS>
class QList
485 return list[0].lock();
527 return next_locked();
532 for (
unsigned i = 0; i < ITEMS; ++i)
561 for (
unsigned i = 0; i < ITEMS; ++i)
589 for (
unsigned i = 0; i < ITEMS; ++i)
615template <
class T>
class QueueWait :
public Q <T>,
public OSSem
674 T *timedwait(
long long timeout)
676 if (OSSem::timedwait(timeout) != 0)
705template <
class T>
class QueueProtectedWait :
public QProtected <T>,
public OSSem
717 ~QueueProtectedWait()
726 QProtected<T>::insert(item);
730#if OPENMRN_FEATURE_RTOS_FROM_ISR
734 void insert_from_isr(T *item)
736 QProtected<T>::insert_locked(item);
746 T *result = QProtected<T>::next();
762 T *result = QProtected<T>::next();
775 T *timedwait(
long long timeout)
777 if (OSSem::timedwait(timeout) != 0)
783 T *result = QProtected<T>::next();
808template <
unsigned items>
836#if OPENMRN_FEATURE_RTOS_FROM_ISR
841 void insert_from_isr(
QMember *item,
unsigned index)
845 this->post_from_isr(&woken);
850 typedef typename QListProtected<items>::Result
Result;
858 if (result.
item != NULL)
874 if (result.
item == NULL)
881#if OPENMRN_FEATURE_SEM_TIMEDWAIT
887 Result timedwait(
long long timeout)
889 if (OSSem::timedwait(timeout) != 0)
896 if (result.
item == NULL)
static OSEvent wakeup
event used to wakeup select calls
See OSMutexLock in os/OS.hxx.
Lightweight locking class for protecting small critical sections.
An object that can be scheduled on an executor to run.
virtual void alloc_result(QMember *item)
Return the result of an alloc_async() from a memory Pool.
This class provides a counting semaphore API.
void post()
Post (increment) a semaphore.
void wait()
Wait on (decrement) a semaphore.
Asynchronous specialization of Q.
bool waiting
true if someone is waiting for an insertion
bool empty()
Test if the queue is empty.
Result next()
Get an item from the front of the queue.
void next_async(Executable *flow)
Get an item from the front of the queue.
QAsync()
Default Constructor.
void insert(QMember *item, unsigned index=0)
Add an item to the back of the queue.
size_t pending(unsigned index)
Get the number of pending items in the queue.
~QAsync()
Default destructor.
QMember * next(unsigned index)
Get an item from the front of the queue.
bool empty(unsigned index)
Test if the queue is empty.
Q impl_
Implementation helper.
size_t pending()
Get the number of pending items in the queue.
Result next_locked()
Get an item from the front of the queue.
A BufferQueue that adds the ability to wait on the next buffer.
void wakeup()
Wakeup anyone waiting on the wait queue.
Result wait()
Wait for an item from the front of the queue.
void insert(QMember *item, unsigned index)
Add an item to the back of the queue.
QListProtected< items >::Result Result
Translate the Result type.
Result next()
Get an item from the front of the queue.
QListProtectedWait()
Default Constructor.
~QListProtectedWait()
Default destructor.
bool empty()
Test if all the queues are empty.
size_t pending()
Get the total number of pending items in all queues in the list.
Result next()
Get an item from the front of the queue queue in priority order.
QList()
Default Constructor.
Q list[ITEMS]
the list of queues
void insert(QMember *item, unsigned index)
Add an item to the back of the queue.
QMember * next(unsigned index)
Get an item from the front of the queue.
size_t pending(unsigned index)
Get the number of pending items in the queue.
bool empty(unsigned index)
Test if the queue is empty.
void insert_locked(QMember *item, unsigned index)
Add an item to the back of the queue.
Essentially a "next" pointer container.
QMember * next
pointer to the next member in the queue
This class implements a linked list "queue" of buffers.
size_t pending()
Get the number of pending items in the queue.
QMember * head
head item in queue
void insert_locked(QMember *item, unsigned index=0)
Add an item to the back of the queue.
Result next_locked()
Get an item from the front of the queue.
void insert(QMember *item, unsigned index=0)
Add an item to the back of the queue.
size_t pending(unsigned index)
Get the number of pending items in the queue.
Result next()
Get an item from the front of the queue.
bool empty()
Test if the queue is empty.
bool empty(unsigned index)
Test if the queue is empty.
QMember * next(unsigned index)
Get an item from the front of the queue.
QMember * tail
tail item in queue
size_t count
number of items in queue
A Notifiable for synchronously waiting for a notification.
void notify() override
Implementation of notification receive.
void wait_for_notification()
Blocks the current thread until the notification is delivered.
Helper class for waiting (blocking the current thread) until a message in the queue shows up.
BlockingWait(TypedQAsync< T > *parent)
Constructor.
T * result_
Response of the allocation.
void run() OVERRIDE
Entry point.
SyncNotifiable n_
helps blocking the calling thread until the allocation is complete.
void alloc_result(QMember *item) OVERRIDE
Return the result of an alloc_async() from a memory Pool.
Strongly typed queue class with asynchronous access.
void typed_insert(T *entry)
Inserts an entry at the end of the queue.
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
#define DIE(MSG)
Unconditionally terminates the current process with a message.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
Result of pulling an item from the queue based on priority.
unsigned index
index of item pulled from queue
QMember * item
item pulled from queue
Result()
Defualt Constructor.
Result(QMember *item, unsigned index)
Explicit initializer constructor.
~Result()
Default Destructor.