|
Open Model Railroad Network (OpenMRN)
|
ScheduledQueue is a queue with multiple priorities, where each priority is a FIFO list. More...
#include <ScheduledQueue.hxx>
Classes | |
| struct | Band |
| This structure contains information about one priority band. More... | |
Public Member Functions | |
| ScheduledQueue (unsigned num_bands, const Fixed16 *strides) | |
| Constructor. | |
| ~ScheduledQueue () | |
| Destructor. | |
| Result | next () |
| Get an item from the queue. | |
| Result | next_locked () |
| Get an item from the queue. | |
| OSMutex * | lock () |
| The caller must acquire this lock before using any of the _locked() functions. | |
| void | insert (QMember *item, unsigned prio) |
| Adds an entry to the queue. | |
| void | insert_locked (QMember *item, unsigned prio) |
| Adds an entry to the queue. | |
| size_t | pending (unsigned prio) |
| Get the number of pending items in the queue. | |
| size_t | pending () const |
| Get the number of pending items in the queue (all bands total) | |
| bool | empty () const |
| unsigned | num_prio () const |
Private Attributes | |
| OSMutex | lock_ |
| Protects insert and next operations. | |
| unsigned | numBands_ |
| How many priority bands we have. | |
| unsigned | numPending_ {0} |
| How many queue entries are pending. | |
| Band * | bands_ |
| The actual priority bands. | |
ScheduledQueue is a queue with multiple priorities, where each priority is a FIFO list.
The different priorities are polled according to a weighted stride scheduler instead of in strict numerical priority order.
Definition at line 47 of file ScheduledQueue.hxx.
|
inline |
Constructor.
| num_bands | now many priority bands should there be. |
| strides | is an array of the size num_bands. It contains the stride coefficients (they should all be numbers <= 1. A value of 1 degrades to strict priority order). This array is not used anymore after the constructor returns. A stride of 0.2 means that 20% of all tokens at this level will be allocated to this band, and 80% of the tokens are passed down to lower priorities (bands with higher index). |
Definition at line 58 of file ScheduledQueue.hxx.
|
inline |
Destructor.
Definition at line 70 of file ScheduledQueue.hxx.
|
inline |
Definition at line 185 of file ScheduledQueue.hxx.
|
inline |
Adds an entry to the queue.
It will be added to the end of the given priority band.
| item | the entry to be added to the queue. |
| prio | which priority band to add to. 0 = highest priority. Must be within 0 and numBands_ - 1. |
Definition at line 150 of file ScheduledQueue.hxx.
|
inline |
Adds an entry to the queue.
It will be added to the end of the given priority band. The caller must hold lock().
| item | the entry to be added to the queue. |
| prio | which priority band to add to. 0 = highest priority. Must be within 0 and numBands_ - 1. |
Definition at line 161 of file ScheduledQueue.hxx.
|
inline |
The caller must acquire this lock before using any of the _locked() functions.
If the caller needs to do many operations in quick succession, it might be faster to do them under a single lock, i.e. acquire lock() first, then call xxx_locked() repeatedly, then unlock.
Definition at line 140 of file ScheduledQueue.hxx.
|
inline |
Get an item from the queue.
The returned item will be according to the priority scheduler.
Definition at line 78 of file ScheduledQueue.hxx.
|
inline |
Get an item from the queue.
The returned item will be according to the priority scheduler. The caller must acquire the lock() first.
Definition at line 87 of file ScheduledQueue.hxx.
|
inline |
Definition at line 191 of file ScheduledQueue.hxx.
|
inline |
Get the number of pending items in the queue (all bands total)
Definition at line 179 of file ScheduledQueue.hxx.
|
inline |
Get the number of pending items in the queue.
| prio | in the list to operate on |
Definition at line 171 of file ScheduledQueue.hxx.
|
private |
The actual priority bands.
Definition at line 220 of file ScheduledQueue.hxx.
|
private |
Protects insert and next operations.
Definition at line 211 of file ScheduledQueue.hxx.
|
private |
How many priority bands we have.
Definition at line 214 of file ScheduledQueue.hxx.
|
private |
How many queue entries are pending.
Definition at line 217 of file ScheduledQueue.hxx.