Records informations about a periodic slot. More...
#include <OSDLPeriodicSlot.h>
Public Member Functions | |
PeriodicSlot (Events::Period periodicity) | |
Creates a scheduler slot for given non-null periodicity, expressed in simulation ticks. | |
~PeriodicSlot () throw () | |
Non-virtual destructor. | |
Events::Period | add (PeriodicalActiveObject &newObject) |
Adds a new periodical active object to that slot. | |
void | removeFromSubslot (PeriodicalActiveObject &object) |
Removes specified periodical object from specified sub-slot, and updates the slot weight. | |
bool | onNextTick (Events::SimulationTick newTick) |
Activates all objects registered in the sub-slot corresponding to this new tick. | |
void | onSimulationSkipped (Events::SimulationTick skipped) |
Notifies all relevant objects that specified simulation tick had to be skipped. | |
Events::Period | getPeriod () const |
Returns the period this slot is in charge of. | |
bool | isEmpty () const |
Returns true iff the slot is fully empty,, i.e. | |
const std::string | toString (Ceylan::VerbosityLevels level=Ceylan::high) const |
Returns an user-friendly description of the state of this object. | |
Protected Member Functions | |
Events::Period | getSubSlotForSimulationTick (Events::SimulationTick tick) const |
Returns the sub-slot number corresponding to specified simulation tick. | |
Events::Period | getLeastBusySubSlot () const |
Returns the first sub-slot whose total object weight is minimal for this periodic slot. | |
void | addInSubSlot (PeriodicalActiveObject &newObject, Events::Period targetSubSlot) |
Adds explicitly in specified sub-slot the active object. | |
bool | activateAllObjectsInSubSlot (Events::Period subSlot, Events::SimulationTick currentTime) |
Activates in turn all active objects registered in the specified sub-slot, from the first object ever registered to the last, if they had not been activated before. | |
Protected Attributes | |
Events::Period | _period |
Stores the periodicity, expressed in simulation ticks, of this slot. | |
Events::Period | _currentSubSlot |
Records the slot corresponding to current simulation tick. | |
ListOfPeriodicalActiveObjects ** | _subslots |
This is an array of pointers to lists: ListOfPeriodicalActiveObjects * _subslots[]. | |
Weight * | _subslotWeights |
Records the weights of all active objects registered in a slot. | |
Private Member Functions | |
PeriodicSlot (const PeriodicSlot &source) | |
Copy constructor made private to ensure that it will never be called. | |
PeriodicSlot & | operator= (const PeriodicSlot &source) |
Assignment operator made private to ensure that it will never be called. |
Records informations about a periodic slot.
Each of these periodic slots is internally divided into as many sub-slots as the length of that slot period.
Each registered periodical active object will then be listed in exactly one sub-slot.
For example, when a PeriodicSlot will be created to manage all objects relying on a periodicity of 7 simulation ticks, that slot will have internally an array of 7 sub-slots. At each new simulation tick, all objects registered in the corresponding sub-slot (whose number will be: new simulation tick % 7), will be activated.
So, at a given simulation tick, all objects put in corresponding sub-slot will be activated. On the next tick, the list corresponding to the next sub-slot will be activated, and so on. Each object registered in a sub-slot will therefore be activated at the right frequency, as defined in the slot, whereas not all of these objects are activated at the same simulation time, to avoid unbalanced load.
A PeriodicSlot does not have to manage simulation time internally, it therefore fully relies on the scheduler to pass it correct simulation ticks.
Definition at line 94 of file OSDLPeriodicSlot.h.
OSDL::Engine::PeriodicSlot::PeriodicSlot | ( | Events::Period | periodicity | ) | [explicit] |
Creates a scheduler slot for given non-null periodicity, expressed in simulation ticks.
periodicity | the chosen periodicity. |
PeriodicSlot::~PeriodicSlot | ( | ) | throw () |
Non-virtual destructor.
Definition at line 67 of file OSDLPeriodicSlot.cc.
References _period, _subslots, _subslotWeights, and OSDL::Video::Pixels::toString().
OSDL::Engine::PeriodicSlot::PeriodicSlot | ( | const PeriodicSlot & | source | ) | [explicit, private] |
Copy constructor made private to ensure that it will never be called.
The compiler should complain whenever this undefined constructor is called, implicitly or not.
bool OSDL::Engine::PeriodicSlot::activateAllObjectsInSubSlot | ( | Events::Period | subSlot, | |
Events::SimulationTick | currentTime | |||
) | [protected] |
Activates in turn all active objects registered in the specified sub-slot, from the first object ever registered to the last, if they had not been activated before.
Each of them is given the specified simulation time.
subSlot | the sub-slot corresponding to this simulation tick for this periodicity. For example, for a periodicity of 7 simulation ticks, the selected sub-slot could be (current simulation tick) % 7. | |
currentTime | the simulation time which should be given to activated objects. |
Period PeriodicSlot::add | ( | PeriodicalActiveObject & | newObject | ) |
Adds a new periodical active object to that slot.
It will be registered in a sub-slot, depending on its scheduling policy.
The slot weight will be updated.
SchedulingException | if the operation failed. |
Definition at line 112 of file OSDLPeriodicSlot.cc.
References _currentSubSlot, _period, addInSubSlot(), getLeastBusySubSlot(), OSDL::Engine::ActiveObject::getPolicy(), OSDL::Engine::relaxed, and OSDL::Engine::strict.
Referenced by OSDL::Engine::Scheduler::registerPeriodicalObject().
void OSDL::Engine::PeriodicSlot::addInSubSlot | ( | PeriodicalActiveObject & | newObject, | |
Events::Period | targetSubSlot | |||
) | [protected] |
Adds explicitly in specified sub-slot the active object.
Referenced by add().
Period PeriodicSlot::getLeastBusySubSlot | ( | ) | const [protected] |
Returns the first sub-slot whose total object weight is minimal for this periodic slot.
Definition at line 418 of file OSDLPeriodicSlot.cc.
References _period, and _subslotWeights.
Referenced by add().
Period PeriodicSlot::getPeriod | ( | ) | const |
Returns the period this slot is in charge of.
Definition at line 313 of file OSDLPeriodicSlot.cc.
References _period.
Events::Period OSDL::Engine::PeriodicSlot::getSubSlotForSimulationTick | ( | Events::SimulationTick | tick | ) | const [protected] |
Returns the sub-slot number corresponding to specified simulation tick.
tick | the simulation tick to be translated into a sub-slot number for this periodic slot. |
bool PeriodicSlot::isEmpty | ( | ) | const |
Returns true iff the slot is fully empty,, i.e.
none of its sub-slots contains any object.
Definition at line 322 of file OSDLPeriodicSlot.cc.
bool OSDL::Engine::PeriodicSlot::onNextTick | ( | Events::SimulationTick | newTick | ) |
Activates all objects registered in the sub-slot corresponding to this new tick.
No blocking checking that no simulation tick was skipped is performed at the level of the periodic slot.
void OSDL::Engine::PeriodicSlot::onSimulationSkipped | ( | Events::SimulationTick | skipped | ) |
Notifies all relevant objects that specified simulation tick had to be skipped.
Called by the scheduler whenever a simulation tick has to be skipped.
SchedulingException | if an object is unable to overcome a simulation skip (reserve it to special uncommon fatal cases, since skips may happen at any time on most computers). |
PeriodicSlot& OSDL::Engine::PeriodicSlot::operator= | ( | const PeriodicSlot & | source | ) | [private] |
Assignment operator made private to ensure that it will never be called.
The compiler should complain whenever this undefined operator is called, implicitly or not.
void PeriodicSlot::removeFromSubslot | ( | PeriodicalActiveObject & | object | ) |
Removes specified periodical object from specified sub-slot, and updates the slot weight.
SchedulingException | if the operation failed. |
Definition at line 150 of file OSDLPeriodicSlot.cc.
References _subslots, _subslotWeights, OSDL::Video::Pixels::toString(), and toString().
Referenced by OSDL::Engine::Scheduler::unregisterPeriodicalObject().
const string PeriodicSlot::toString | ( | Ceylan::VerbosityLevels | level = Ceylan::high |
) | const |
Returns an user-friendly description of the state of this object.
level | the requested verbosity level. |
Definition at line 340 of file OSDLPeriodicSlot.cc.
References _currentSubSlot, _period, _subslots, _subslotWeights, and OSDL::Video::Pixels::toString().
Referenced by removeFromSubslot().
Records the slot corresponding to current simulation tick.
Definition at line 299 of file OSDLPeriodicSlot.h.
Referenced by add(), and toString().
Events::Period OSDL::Engine::PeriodicSlot::_period [protected] |
Stores the periodicity, expressed in simulation ticks, of this slot.
Definition at line 294 of file OSDLPeriodicSlot.h.
Referenced by add(), getLeastBusySubSlot(), getPeriod(), isEmpty(), toString(), and ~PeriodicSlot().
This is an array of pointers to lists: ListOfPeriodicalActiveObjects * _subslots[].
The pointed array has as many elements (sub-slots) as constructor-specified periodicity.
Ex: for a period of 3, we have list #0, #1 and #2.
Definition at line 313 of file OSDLPeriodicSlot.h.
Referenced by isEmpty(), removeFromSubslot(), toString(), and ~PeriodicSlot().
Weight* OSDL::Engine::PeriodicSlot::_subslotWeights [protected] |
Records the weights of all active objects registered in a slot.
Definition at line 322 of file OSDLPeriodicSlot.h.
Referenced by getLeastBusySubSlot(), removeFromSubslot(), toString(), and ~PeriodicSlot().