StuBS
|
Manages and activates time-triggered activities. More...
#include <bellringer.h>
Public Member Functions | |
void | check () |
Checks whether there are bells to be rung. | |
void | job (Bell *bell, unsigned int ms) |
Passes a bell to the bellringer to be rung after ms milliseconds. | |
void | cancel (Bell *bell) |
Cancel ticking & ringing a bell. | |
bool | bellPending () |
Checks whether there are enqueued bells. | |
Private Attributes | |
Queue< Bell > | bells |
List of bells currently managed. | |
Manages and activates time-triggered activities.
The Bellringer is regularly activated and checks whether any of the bells should ring. The bells are stored in a Queue<Bell> that is managed by the Bellringer. A clever implementation avoids iterating through the whole list for every iteration by keeping the bells sorted and storing delta times. This approach leads to a complexity of O(1) for the method called by the timer interrupt in case no bells need to be rung.
bool Bellringer::bellPending | ( | ) |
Checks whether there are enqueued bells.
void Bellringer::cancel | ( | Bell * | bell | ) |
Cancel ticking & ringing a bell.
bell | Bell that should not be rung. |
void Bellringer::check | ( | ) |
Checks whether there are bells to be rung.
Every call to check elapses a tick. Once such a tick reduces a bells remaining time to zero, the bell will be rung.
void Bellringer::job | ( | Bell * | bell, |
unsigned int | ms ) |
Passes a bell
to the bellringer to be rung after ms
milliseconds.
bell | Bell that should be rung after ms milliseconds |
ms | number of milliseconds that should be waited before ringing the bell |