Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
ScheduledQueue Class Reference

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.
 
OSMutexlock ()
 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.
 
Bandbands_
 The actual priority bands.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ScheduledQueue()

ScheduledQueue::ScheduledQueue ( unsigned  num_bands,
const Fixed16 strides 
)
inline

Constructor.

Parameters
num_bandsnow many priority bands should there be.
stridesis 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.

◆ ~ScheduledQueue()

ScheduledQueue::~ScheduledQueue ( )
inline

Destructor.

Definition at line 70 of file ScheduledQueue.hxx.

Member Function Documentation

◆ empty()

bool ScheduledQueue::empty ( ) const
inline
Returns
true if the queue is empty (on all priority bands).

Definition at line 185 of file ScheduledQueue.hxx.

◆ insert()

void ScheduledQueue::insert ( QMember item,
unsigned  prio 
)
inline

Adds an entry to the queue.

It will be added to the end of the given priority band.

Parameters
itemthe entry to be added to the queue.
priowhich priority band to add to. 0 = highest priority. Must be within 0 and numBands_ - 1.

Definition at line 150 of file ScheduledQueue.hxx.

◆ insert_locked()

void ScheduledQueue::insert_locked ( QMember item,
unsigned  prio 
)
inline

Adds an entry to the queue.

It will be added to the end of the given priority band. The caller must hold lock().

Parameters
itemthe entry to be added to the queue.
priowhich priority band to add to. 0 = highest priority. Must be within 0 and numBands_ - 1.

Definition at line 161 of file ScheduledQueue.hxx.

◆ lock()

OSMutex * ScheduledQueue::lock ( )
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.

Returns
the lock to use for the _locked() functions.

Definition at line 140 of file ScheduledQueue.hxx.

◆ next()

Result ScheduledQueue::next ( )
inline

Get an item from the queue.

The returned item will be according to the priority scheduler.

Returns
the member and the priority from which it came.

Definition at line 78 of file ScheduledQueue.hxx.

◆ next_locked()

Result ScheduledQueue::next_locked ( )
inline

Get an item from the queue.

The returned item will be according to the priority scheduler. The caller must acquire the lock() first.

Returns
the member and the priority from which it came.

Definition at line 87 of file ScheduledQueue.hxx.

◆ num_prio()

unsigned ScheduledQueue::num_prio ( ) const
inline
Returns
the number of available priority bands.

Definition at line 191 of file ScheduledQueue.hxx.

◆ pending() [1/2]

size_t ScheduledQueue::pending ( ) const
inline

Get the number of pending items in the queue (all bands total)

Returns
number of pending items

Definition at line 179 of file ScheduledQueue.hxx.

◆ pending() [2/2]

size_t ScheduledQueue::pending ( unsigned  prio)
inline

Get the number of pending items in the queue.

Parameters
prioin the list to operate on
Returns
number of pending items in that priority band in the queue

Definition at line 171 of file ScheduledQueue.hxx.

Member Data Documentation

◆ bands_

Band* ScheduledQueue::bands_
private

The actual priority bands.

Definition at line 220 of file ScheduledQueue.hxx.

◆ lock_

OSMutex ScheduledQueue::lock_
private

Protects insert and next operations.

Definition at line 211 of file ScheduledQueue.hxx.

◆ numBands_

unsigned ScheduledQueue::numBands_
private

How many priority bands we have.

Definition at line 214 of file ScheduledQueue.hxx.

◆ numPending_

unsigned ScheduledQueue::numPending_ {0}
private

How many queue entries are pending.

Definition at line 217 of file ScheduledQueue.hxx.


The documentation for this class was generated from the following file: