#include <OSDLPeriodicSlot.h>
Each of these periodic slots is internally divided into as many sub-slots as the period length. Each registered active object will be listed in at least a sub-slot.
For example, for a periodicity of 7 simulation steps, a dedicated PeriodicSlot will be created. It will be in charge of all objects registered for this periodicity, and will have internally a list 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 step, all objects put in corresponding sub-slot will be activated. On the next step, 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 in 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 64 of file OSDLPeriodicSlot.h.
Public Member Functions | |
PeriodicSlot (Events::Period periodicity) throw () | |
Creates a scheduler slot for given non-null periodicity, expressed in simulation ticks. | |
~PeriodicSlot () throw () | |
Non-virtual destructor. | |
void | add (ActiveObject &newObject) throw ( SchedulingException ) |
Adds a new active object. | |
void | remove (ActiveObject &object) throw ( SchedulingException ) |
Removes entirely an active object, possibly registered multiple time, from its slot. | |
void | onNextTick (Events::SimulationTick newTick) throw () |
Activates all objects registered in the slot corresponding on this new tick. | |
void | onSimulationSkipped (Events::SimulationTick skipped) throw ( SchedulingException ) |
Notices all relevant objects that specified simulation tick has to be skipped. | |
Events::Period | getPeriod () throw () |
Returns the period this slot is in charge of. | |
const std::string | toString (Ceylan::VerbosityLevels level=Ceylan::high) const throw () |
Returns an user-friendly description of the state of this object. | |
Protected Member Functions | |
Events::Period | getSubSlotForSimulationTick (Events::SimulationTick tick) const throw () |
Returns the sub-slot number corresponding to specified simulation tick. | |
void | addInSlot (ActiveObject &newObject, Events::Period targetSlot) throw () |
Adds explicitly in specified slot the active object. | |
bool | removeFromSlot (ActiveObject &object, Events::Period targetSlot) throw ( SchedulingException) |
Removes from specified slot all subscriptions of the active object, and updates the slot weight. | |
Events::Period | getLeastBusySlot () const throw () |
Returns the first slot whose total object weights is minimal for this periodic slot. | |
void | activateAllObjectsInSubSlot (Events::Period subSlot, Events::SimulationTick currentTime) throw () |
Activates in turn all active objects registered in the specified 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 steps, of this slot. | |
Events::Period | _currentSlot |
Records the slot corresponding to current simulation step. | |
ListOfActiveObjects ** | _slots |
This is an array of pointers to lists : ListOfActiveObjects * _slots[]. | |
Weight * | _slotWeights |
Records the weights of all active objects registered in a slot. | |
Private Member Functions | |
PeriodicSlot (const PeriodicSlot &source) throw () | |
Copy constructor made private to ensure that it will never be called. | |
PeriodicSlot & | operator= (const PeriodicSlot &source) throw () |
Assignment operator made private to ensure that it will never be called. |
PeriodicSlot::PeriodicSlot | ( | Events::Period | periodicity | ) | throw () [explicit] |
Creates a scheduler slot for given non-null periodicity, expressed in simulation ticks.
periodicity | the chosen periodicity. |
Definition at line 14 of file OSDLPeriodicSlot.cc.
PeriodicSlot::~PeriodicSlot | ( | ) | throw () |
Non-virtual destructor.
Definition at line 39 of file OSDLPeriodicSlot.cc.
References _period, _slots, and _slotWeights.
OSDL::Engine::PeriodicSlot::PeriodicSlot | ( | const PeriodicSlot & | source | ) | throw () [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.
void PeriodicSlot::add | ( | ActiveObject & | newObject | ) | throw ( SchedulingException ) |
Adds a new active object.
It will be registered in a slot, depending on its scheduling policy.
SchedulingException | if the operation failed. |
Definition at line 58 of file OSDLPeriodicSlot.cc.
References OSDL::Engine::relaxed, and OSDL::Engine::strict.
void PeriodicSlot::remove | ( | ActiveObject & | object | ) | throw ( SchedulingException ) |
Removes entirely an active object, possibly registered multiple time, from its slot.
SchedulingException | if the object was not found in any sub-slot of the slot. |
Definition at line 93 of file OSDLPeriodicSlot.cc.
void PeriodicSlot::onNextTick | ( | Events::SimulationTick | newTick | ) | throw () |
Activates all objects registered in the slot corresponding on this new tick.
Definition at line 111 of file OSDLPeriodicSlot.cc.
References OSDL::Video::Pixels::toString().
void PeriodicSlot::onSimulationSkipped | ( | Events::SimulationTick | skipped | ) | throw ( SchedulingException ) |
Notices all relevant objects that specified simulation tick has 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). |
Definition at line 169 of file OSDLPeriodicSlot.cc.
Period PeriodicSlot::getPeriod | ( | ) | throw () |
Returns the period this slot is in charge of.
Definition at line 190 of file OSDLPeriodicSlot.cc.
References _period.
const string PeriodicSlot::toString | ( | Ceylan::VerbosityLevels | level = Ceylan::high |
) | const throw () |
Returns an user-friendly description of the state of this object.
level | the requested verbosity level. |
Periodic slots do not really implement the Ceylan::TextDisplayable interface, since the signature of the toString would require it is virtual, whereas this object is designed so that it has no virtual member, hence no virtual table overhead.
Definition at line 198 of file OSDLPeriodicSlot.cc.
References OSDL::Video::Pixels::toString().
Period PeriodicSlot::getSubSlotForSimulationTick | ( | Events::SimulationTick | tick | ) | const throw () [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. |
Definition at line 248 of file OSDLPeriodicSlot.cc.
void PeriodicSlot::addInSlot | ( | ActiveObject & | newObject, | |
Events::Period | targetSlot | |||
) | throw () [protected] |
Adds explicitly in specified slot the active object.
Definition at line 257 of file OSDLPeriodicSlot.cc.
bool PeriodicSlot::removeFromSlot | ( | ActiveObject & | object, | |
Events::Period | targetSlot | |||
) | throw ( SchedulingException) [protected] |
Removes from specified slot all subscriptions of the active object, and updates the slot weight.
Definition at line 270 of file OSDLPeriodicSlot.cc.
Period PeriodicSlot::getLeastBusySlot | ( | ) | const throw () [protected] |
Returns the first slot whose total object weights is minimal for this periodic slot.
Definition at line 309 of file OSDLPeriodicSlot.cc.
References _period, and _slotWeights.
void PeriodicSlot::activateAllObjectsInSubSlot | ( | Events::Period | subSlot, | |
Events::SimulationTick | currentTime | |||
) | throw () [protected] |
Activates in turn all active objects registered in the specified 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. |
Definition at line 329 of file OSDLPeriodicSlot.cc.
PeriodicSlot& OSDL::Engine::PeriodicSlot::operator= | ( | const PeriodicSlot & | source | ) | throw () [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.
Events::Period OSDL::Engine::PeriodicSlot::_period [protected] |
Stores the periodicity, expressed in simulation steps, of this slot.
Definition at line 250 of file OSDLPeriodicSlot.h.
Referenced by getLeastBusySlot(), getPeriod(), and ~PeriodicSlot().
Records the slot corresponding to current simulation step.
Definition at line 254 of file OSDLPeriodicSlot.h.
ListOfActiveObjects** OSDL::Engine::PeriodicSlot::_slots [protected] |
This is an array of pointers to lists : ListOfActiveObjects * _slots[].
The pointed array has as many elements (slots) as constructor-specified periodicity.
Definition at line 265 of file OSDLPeriodicSlot.h.
Referenced by ~PeriodicSlot().
Weight* OSDL::Engine::PeriodicSlot::_slotWeights [protected] |
Records the weights of all active objects registered in a slot.
Definition at line 273 of file OSDLPeriodicSlot.h.
Referenced by getLeastBusySlot(), and ~PeriodicSlot().