Deleted Added
sdiff udiff text old ( 13140:ecd8a58f3884 ) new ( 13144:61e0f3230787 )
full compact
1/*
2 * Copyright 2018 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright

--- 131 unchanged lines hidden (view full) ---

140 * priority which is lower than all the others except the ready event. Timed
141 * notifications will happen before it fires, but it will override any ready
142 * event and prevent the evaluate phase from starting.
143 */
144
145class Scheduler
146{
147 public:
148 typedef std::set<ScEvent *> ScEvents;
149
150 class TimeSlot : public ::Event
151 {
152 public:
153 TimeSlot() : ::Event(Default_Pri, AutoDelete) {}
154
155 ScEvents events;
156 void process();

--- 64 unchanged lines hidden (view full) ---

221 // For scheduling delayed/timed notifications/timeouts.
222 void
223 schedule(ScEvent *event, const ::sc_core::sc_time &delay)
224 {
225 Tick tick = delayed(delay);
226 if (tick < getCurTick())
227 tick = getCurTick();
228
229 event->schedule(tick);
230
231 // Delta notification/timeout.
232 if (delay.value() == 0) {
233 deltas.insert(event);
234 scheduleReadyEvent();
235 return;
236 }
237
238 // Timed notification/timeout.
239 TimeSlot *&ts = timeSlots[tick];
240 if (!ts) {
241 ts = new TimeSlot;
242 schedule(ts, tick);
243 }
244 ts->events.insert(event);
245 }
246
247 // For descheduling delayed/timed notifications/timeouts.
248 void
249 deschedule(ScEvent *event)
250 {
251 if (event->when() == getCurTick()) {
252 // Attempt to remove from delta notifications.
253 if (deltas.erase(event) == 1) {
254 event->deschedule();
255 return;
256 }
257 }
258
259 // Timed notification/timeout.
260 auto tsit = timeSlots.find(event->when());
261 panic_if(tsit == timeSlots.end(),
262 "Descheduling event at time with no events.");
263 TimeSlot *ts = tsit->second;
264 ScEvents &events = ts->events;
265 assert(events.erase(event));
266 event->deschedule();
267
268 // If no more events are happening at this time slot, get rid of it.
269 if (events.empty()) {
270 deschedule(ts);
271 timeSlots.erase(tsit);
272 }
273 }

--- 145 unchanged lines hidden (view full) ---

419 std::map<::Event *, Tick> eventsToSchedule;
420};
421
422extern Scheduler scheduler;
423
424inline void
425Scheduler::TimeSlot::process()
426{
427 for (auto &e: events)
428 e->run();
429 scheduler.completeTimeSlot(this);
430}
431
432} // namespace sc_gem5
433
434#endif // __SYSTEMC_CORE_SCHEDULER_H__