The Sparta Modeling Framework
Loading...
Searching...
No Matches
PhasedUniqueEvent.hpp
Go to the documentation of this file.
1// <PhasedUniqueEvent.h> -*- C++ -*-
2
3
10#pragma once
11
12#include <set>
13#include <memory>
16
17namespace sparta
18{
19
32 {
33 public:
47 const std::string & name,
48 SchedulingPhase sched_phase,
49 const SpartaHandler & consumer_event_handler,
50 Clock::Cycle delay = 0) :
51 EventNode(event_set, name, sched_phase),
52 Scheduleable(CREATE_SPARTA_HANDLER(PhasedUniqueEvent, deliverEvent_), delay, sched_phase, true),
53 pue_consumer_event_handler_(consumer_event_handler),
54 fancy_name_(name + "[" + consumer_event_handler.getName() + "]")
55 {
58 setLabel(fancy_name_.c_str());
59 }
60
63
66
68 Scheduler * getScheduler(const bool must_exist = true) {
69 return Scheduleable::getScheduler(must_exist);
70 }
71
73 const Scheduler * getScheduler(const bool must_exist = true) const {
74 return Scheduleable::getScheduler(must_exist);
75 }
76
78 virtual ~PhasedUniqueEvent() {}
79
82
85
91 sparta::Scheduler * scheduler) override final
92 {
94 sparta_assert(last_tick_called_ != (scheduler->getCurrentTick() + rel_tick),
95 "PhasedUniqueEvent (UniqueEvent) '" << getName()
96 << "' was already scheduled and fired this cycle."
97 "\t\nAre you missing a precedence rule?");
98
99 Scheduleable::scheduleRelativeTick(rel_tick, scheduler);
100 }
101
102#ifndef DO_NOT_DOCUMENT
103 // Used by EventNode and auto-precedence. Return the
104 // Scheduleable (this)
105 Scheduleable & getScheduleable() override {
106 return *this;
107 }
108#endif
109
110 private:
111
115 void deliverEvent_() {
116 // I don't like this, but since there are a couple of
117 // legal ways to create the PhasedUniqueEvent (one includes the
118 // lack of a clock), I cannot remember the time...
119 if(SPARTA_EXPECT_TRUE(local_clk_ != nullptr)) {
120 last_tick_called_ = local_clk_->getScheduler()->getCurrentTick();
121 }
122 pue_consumer_event_handler_();
123 }
124
126 void createResource_() override {
129 }
130
132 SpartaHandler pue_consumer_event_handler_;
133
135 Scheduler::Tick last_tick_called_ = Scheduler::Tick(-1);
136
138 std::string fancy_name_;
139 };
140
141}
File that defines the EventNode class.
File that defines the Scheduleable class.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
#define SPARTA_EXPECT_TRUE(x)
A macro for hinting to the compiler a particular condition should be considered most likely true.
#define CREATE_SPARTA_HANDLER(clname, meth)
Scheduler * getScheduler() const
Definition Clock.hpp:302
EventNode is the base class for all event types in SPARTA. Not to be used by the modeler....
Definition EventNode.hpp:36
sparta::SchedulingPhase getSchedulingPhase() const
Get the scheduling phase of this event node.
Definition EventNode.hpp:93
virtual Scheduleable & getScheduleable()=0
Get the scheduleable associated with this event node.
static Scheduler * determineScheduler(const Clock *clk)
Center point of Scheduler location.
Definition EventNode.hpp:71
A type of Event that uniquely schedules itself on the schedule within a single time quantum....
PhasedUniqueEvent & operator=(const PhasedUniqueEvent &)=delete
Disallow the assignment of the PhasedUniqueEvent.
PhasedUniqueEvent(const PhasedUniqueEvent &)=delete
Disallow the copying of the PhasedUniqueEvent.
Scheduler * getScheduler(const bool must_exist=true)
Get the scheduler this Scheduleable is assigned to.
void scheduleRelativeTick(sparta::Scheduler::Tick rel_tick, sparta::Scheduler *scheduler) override final
Schedule at time rel_tick.
virtual ~PhasedUniqueEvent()
Uniquely destroy.
PhasedUniqueEvent(TreeNode *event_set, const std::string &name, SchedulingPhase sched_phase, const SpartaHandler &consumer_event_handler, Clock::Cycle delay=0)
Create a PhasedUniqueEvent. The recommendation is to use the EventSet::createEvent method to create o...
const Scheduler * getScheduler(const bool must_exist=true) const
Get the scheduler this Scheduleable is assigned to.
A class that defines the basic scheduling interface to the Scheduler. Not intended to be used by mode...
virtual void scheduleRelativeTick(const Scheduler::Tick rel_tick, Scheduler *const scheduler)
Schedule this event on a relative scheduler tick.
void schedule()
Schedule this event with its pre-set delay using the pre-set Clock.
Scheduler * getScheduler(const bool must_exist=true)
Get the scheduler this Scheduleable is assigned to.
void setLabel(const char *label)
Set a new label for this Scheduleable – used in debugging.
PrecedenceSetup scheduler_
Cache a pointer to the scheduler used.
const Clock * local_clk_
A local clock for speed.
A class that lets you schedule events now and in the future.
Tick getCurrentTick() const noexcept
The current tick the Scheduler is working on or just finished.
uint64_t Tick
Typedef for our unit of time.
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
const Clock * getClock() override
Walks up parents (starting with self) until a parent with an associated local clock is found,...
const std::string & getName() const override
Gets the name of this node.
Macros for handling exponential backoff.
SchedulingPhase
The SchedulingPhases used for events (Tick, Update, PortUpdate, etc)