43 using ProxyAllocation = std::vector<std::unique_ptr<PayloadDeliveringProxy>>;
44 using ProxyFreeList = std::vector<PayloadDeliveringProxy *>;
59 "This Payload handle is already scheduled or was previously cancelled. "
60 "To schedule again, you must create a new one");
70 target_consumer_event_handler_(prototype.
getHandler()),
71 loc_(parent_->inflight_pl_.end())
89 void reclaim_()
override {
91 parent_->reclaimProxy_(loc_);
98 void eventCancelled_()
override {
105 void setPayload_(
const DataT & pl) {
111 const DataT & getPayload_()
const {
124 void deliverPayload_() {
126 "Some construct is trying to deliver a payload twice: "
127 << parent_->name_ <<
" to handler: "
128 << target_consumer_event_handler_.getName());
130 target_consumer_event_handler_((
const void*)&payload_);
135 const SpartaHandler target_consumer_event_handler_;
138 bool scheduled_ =
false;
139 bool cancelled_ =
false;
149 proxy = free_pl_[free_idx_];
153 if(allocation_idx_ == allocated_proxies_.size()) {
158 proxy = allocated_proxies_[allocation_idx_].get();
163 "' has allocated over " << inflight_pl_.
max_size() <<
164 " outstanding events -- does that seem right?");
166 proxy->setInFlightLocation_(inflight_pl_.
emplace_back(proxy));
167 proxy->setPayload_(dat);
182 (*pl_location)->setPayload_(
nullptr);
184 free_pl_[free_idx_++] = *pl_location;
185 inflight_pl_.
erase(pl_location);
186 pl_location = inflight_pl_.
end();
202 PhasedPayloadEvent(TreeNode * event_set,
203 const std::string & name,
205 const SpartaHandler & consumer_event_handler,
206 Clock::Cycle delay = 0) :
208 name_(name +
"[" + consumer_event_handler.
getName() +
"]"),
209 prototype_(consumer_event_handler, delay, sched_phase)
212 "You must assign a PhasedPayloadEvent a consumer handler "
213 "that takes exactly one argument");
242 return allocateProxy_(payload);
249 prototype_ >> consumer;
279 return inflight_pl_.
size();
288 for(
auto * proxy : inflight_pl_) {
289 if(proxy->isScheduled(rel_cycle)) {
308 const uint32_t cancel_cnt = inflight_pl_.
size();
311 auto bit = inflight_pl_.
begin();
312 while(bit != inflight_pl_.
end()) {
327 uint32_t
cancel(Clock::Cycle rel_cycle) {
328 const uint32_t cancel_cnt = inflight_pl_.
size();
329 auto bit = inflight_pl_.
begin();
330 while(bit != inflight_pl_.
end()) {
335 proxy->cancel(rel_cycle);
351 uint32_t cancel_cnt = 0;
354 auto bit = inflight_pl_.
begin();
355 while(bit != inflight_pl_.
end()) {
358 if(proxy->getPayload_() == criteria) {
377 std::vector<Scheduleable*> ple_vector;
378 for(
auto * proxy : inflight_pl_)
380 if(proxy->getPayload_() == criteria) {
381 ple_vector.push_back(proxy);
397 for(
auto * proxy : inflight_pl_)
399 if(proxy->getPayload_() == criteria) {
442 uint32_t
cancelIf(std::function<
bool(
const DataT &)> compare) {
443 uint32_t cancel_cnt = 0;
446 auto bit = inflight_pl_.
begin();
447 while(bit != inflight_pl_.
end()) {
450 if(compare(proxy->getPayload_())) {
497 std::vector<Scheduleable*>
getHandleIf(std::function<
bool(
const DataT &)> compare) {
498 std::vector<Scheduleable*> ple_vector;
499 for(
auto * proxy : inflight_pl_) {
500 if(compare(proxy->getPayload_())) {
501 ple_vector.push_back(proxy);
543 uint32_t
confirmIf(std::function<
bool(
const DataT &)> compare) {
544 for(
auto * proxy : inflight_pl_)
546 if(compare(proxy->getPayload_())) {
571 const std::string & name,
573 const SpartaHandler & consumer_event_handler,
574 Clock::Cycle delay = 0) :
576 name_(name +
"[" + consumer_event_handler.
getName() +
"]"),
577 prototype_(consumer_event_handler, delay, sched_phase)
581 "You must assign a PhasedPayloadEvent a consumer handler ""that takes exactly one argument");
588 void createResource_()
override {
599 const uint32_t old_size = allocated_proxies_.size();
600 const uint32_t new_size = payload_proxy_allocation_cadence_ + old_size;
601 allocated_proxies_.resize(new_size);
602 for(uint32_t i = old_size; i < new_size; ++i) {
605 free_pl_.resize(new_size,
nullptr);
612 Scheduleable prototype_;
614 ProxyAllocation allocated_proxies_;
615 ProxyFreeList free_pl_;
616 ProxyInflightList inflight_pl_{1100};
621 const uint32_t payload_proxy_allocation_cadence_ = 16;
622 uint32_t free_idx_ = 0;
623 uint32_t allocation_idx_ = 0;
File that defines the EventNode class.
File that defines the FastList class – an alternative to std::list when the user knows the size of th...
File that defines the Scheduleable class.
File that defines the phases used in simulation.
#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 SPARTA_EXPECT_FALSE(x)
A macro for hinting to the compiler a particular condition should be considered most likely false.
#define CREATE_SPARTA_HANDLER(clname, meth)
File that defines the StartupEvent class.
File that defines a ValidValue.
EventNode is the base class for all event types in SPARTA. Not to be used by the modeler....
EventNode(TreeNode *event_set, const std::string &name, sparta::SchedulingPhase sched_phase)
Create an Event Node.
static Scheduler * determineScheduler(const Clock *clk)
Center point of Scheduler location.
Class to schedule a Scheduleable in the future with a payload, but the class itself is not typed on t...
virtual ~PhasedPayloadEvent()
Destroy!
uint32_t getNumOutstandingEvents() const
Return the number of unfired/unscheduled Payloads.
ScheduleableHandle preparePayload(const DataT &payload)
Prepare a Scheduleable Payload for scheduling either now or later.
uint32_t cancel(Clock::Cycle rel_cycle)
Cancel inflight PayloadEvents at the given relative cycle.
bool isScheduled() const
Is this PhasedPayloadEvent have anything scheduled?
PhasedPayloadEvent< DataT > & operator=(const PhasedPayloadEvent< DataT > &)=delete
No assignments, no copies.
void setContinuing(bool continuing)
This event, if continuing == true, will keep the simulation running.
uint32_t cancelIf(const DataT &criteria)
Cancel any scheduled Payload that matches the given criteria.
uint32_t confirmIf(std::function< bool(const DataT &)> compare)
Confirm if any scheduled payload matches the given criteria.
friend class PayloadDeliveringProxy
Allow the proxy to reclaim itself.
std::vector< Scheduleable * > getHandleIf(std::function< bool(const DataT &)> compare)
Return a vector of scheduleable handles that match the given function.
bool isScheduled(Clock::Cycle rel_cycle) const
Determine if this PhasedPayloadEvent is driven on the given cycle.
uint32_t cancel()
Cancel all inflight PayloadEvents.
PhasedPayloadEvent(const PhasedPayloadEvent< DataT > &)=delete
No assignments, no copies.
Scheduleable & operator>>(Scheduleable &consumer)
uint32_t cancelIf(std::function< bool(const DataT &)> compare)
Cancel any scheduled Payload that matches the given function.
std::vector< Scheduleable * > getHandleIf(const DataT &criteria)
Return a vector of scheduleable handles that match the given criteria.
Scheduleable & getScheduleable() override
Get the scheduleable associated with this event node.
bool confirmIf(const DataT &criteria)
Confirm if any scheduled payload matches the given criteria.
PhasedPayloadEvent(PhasedPayloadEvent< DataT > &&)=delete
No assignments, no copies.
A light-weight reference counting handle for Scheduleables – DOES NOT delete.
A class that defines the basic scheduling interface to the Scheduler. Not intended to be used by mode...
void setContinuing(bool continuing)
This event, if continuing == true, will keep the simulation running.
void setScheduler(Scheduler *sched)
Set the Scheduler of this Scheduleable, and set the local vertex_ to a new vertex from the Vertex Fac...
virtual void scheduleRelativeTick(const Scheduler::Tick rel_tick, Scheduler *const scheduler)
Schedule this event on a relative scheduler tick.
const SpartaHandler & getHandler() const
Get the consumer handler/callback associated with this event.
void setScheduleableClock(const Clock *clk)
Set the clock and scheduler of this Scheduleable.
uint32_t getScheduleableHandleCount_() const
SpartaHandler consumer_event_handler_
The Consumer callback registered with the Event.
A class that lets you schedule events now and in the future.
uint64_t Tick
Typedef for our unit of time.
Node in a composite tree representing a sparta Tree item.
std::string getLocation() const override final
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.
iterator end()
Obtain an end iterator.
iterator begin()
Obtain a beginning iterator.
iterator emplace_back(ArgsT &&...args)
emplace and object at the back
NodeIterator< false > iterator
Iterator type.
iterator erase(const const_iterator &entry)
Erase an element with the given iterator.
Macros for handling exponential backoff.
SchedulingPhase
The SchedulingPhases used for events (Tick, Update, PortUpdate, etc)