The Sparta Modeling Framework
Loading...
Searching...
No Matches
Precedence operators for EventNode/Scheduleables

Ordering events in Sparta is one of the key features Sparta has over other simulation frameworks. Being able to indicate that a modeler requires one event to be scheduled/fired before another is not only handy, but critical to a deterministic model. Sparta enables ordering through precedence operations, documented here.

Sparta main precedence operator is the C++ operator>> and are documented in namespace sparta. An example of setting precedence between two events:

sparta::Event<> * event1(...);
sparta::Event<> event2(...);
// Make sure event1 is always scheduled before event2
event1 >> event2;
Event is a simple class for scheduling random events on the Scheduler.
Definition Event.hpp:42

This code will guarantee that event1 will always be scheduled and fired before event2 in simulation, not matter which event is scheduled first. However, if event2 attempts to schedule event1 on the same cycle, the framework will throw an exception:

void MyUnit::event2Handler()
{
event1.schedule(sparta::Clock::Cycle(0)); // ERROR! Event1 is supposed to fire before event2
}
void MyUnit::event1Handler()
{
event2.schedule(sparta::Clock::Cycle(0)); // OK Event2 is supposed to fire after event1
}

This, however, is ok to do:

void MyUnit::event2Handler()
{
event1.schedule(sparta::Clock::Cycle(1)); // Ok, this is being scheduled next cycle
}

Some combinations:

// Easy
concrete_event >> concrete_event;
// Pointers
event_pointer >> concrete_event;
concrete_event >> event_pointer;
event_pointer >> event_pointer;
// Unique Ptrs
std::unique_ptr<eventT> >> std::unique_ptr<eventT>;
std::unique_ptr<eventT> >> concrete_event;
std::unique_ptr<eventT> >> event_pointer;
concrete_event >> std::unique_ptr<eventT>;
event_pointer >> std::unique_ptr<eventT>;
// GlobalOrderingPoint
sparta::GlobalOrderingPoint gop(node, "gop");
gop >> concrete_event;
gop >> event_pointer;
gop >> std::unique_ptr<eventT>;
concrete_event >> gop;
event_pointer >> gop;
std::unique_ptr<eventT> >> gop;
Used to set precedence between Scheduleable types across simulation.