From e99a575c78735ad9e35e30ee8714d5e2798e3014 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Fri, 31 Aug 2018 16:18:10 -0700 Subject: systemc: Store timed notifications in a list instead of a set. This has three advantages. First, the data structure doesn't have to try to keep track of whether or not an event is already listed there. Second, it's easier to delete an item by storing an iterator for it when it gets inserted. Third, the ordering of events is not dependent on the arbitrary ordering of the set, it's bsaed on the fixed order the events get added to the list. One part of this change makes ScEvent-s keep track of what list they're on, and handle their own insertion and deletion when they're scheduled or descheduled. A side effect of that is that it's no longer safe to simply use a range based for loop to loop over all of an ScEvent and deschedule all its events or to run then (which deschedules them internally once they execute). That can be avoided by looping until the list is empty, and operating on the first element. As the first element is processed and removed from the list, the next element will become first and will get picked up in the next iteration. Change-Id: Icad51a63f153297c88e65f85d22ac721e6c571d8 Reviewed-on: https://gem5-review.googlesource.com/c/12456 Reviewed-by: Gabe Black Maintainer: Gabe Black --- src/systemc/core/scheduler.hh | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'src/systemc/core/scheduler.hh') diff --git a/src/systemc/core/scheduler.hh b/src/systemc/core/scheduler.hh index 2bee0b090..924cfb29e 100644 --- a/src/systemc/core/scheduler.hh +++ b/src/systemc/core/scheduler.hh @@ -145,7 +145,7 @@ typedef NodeList ChannelList; class Scheduler { public: - typedef std::set ScEvents; + typedef std::list ScEvents; class TimeSlot : public ::Event { @@ -226,11 +226,9 @@ class Scheduler if (tick < getCurTick()) tick = getCurTick(); - event->schedule(tick); - // Delta notification/timeout. if (delay.value() == 0) { - deltas.insert(event); + event->schedule(deltas, tick); scheduleReadyEvent(); return; } @@ -241,19 +239,18 @@ class Scheduler ts = new TimeSlot; schedule(ts, tick); } - ts->events.insert(event); + event->schedule(ts->events, tick); } // For descheduling delayed/timed notifications/timeouts. void deschedule(ScEvent *event) { - if (event->when() == getCurTick()) { - // Attempt to remove from delta notifications. - if (deltas.erase(event) == 1) { - event->deschedule(); - return; - } + ScEvents *on = event->scheduledOn(); + + if (on == &deltas) { + event->deschedule(); + return; } // Timed notification/timeout. @@ -262,7 +259,7 @@ class Scheduler "Descheduling event at time with no events."); TimeSlot *ts = tsit->second; ScEvents &events = ts->events; - assert(events.erase(event)); + assert(on == &events); event->deschedule(); // If no more events are happening at this time slot, get rid of it. @@ -424,8 +421,8 @@ extern Scheduler scheduler; inline void Scheduler::TimeSlot::process() { - for (auto &e: events) - e->run(); + while (!events.empty()) + events.front()->run(); scheduler.completeTimeSlot(this); } -- cgit v1.2.3