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::list<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 // Delta notification/timeout. 230 if (delay.value() == 0) { |
231 event->schedule(deltas, tick); |
232 scheduleReadyEvent(); 233 return; 234 } 235 236 // Timed notification/timeout. 237 TimeSlot *&ts = timeSlots[tick]; 238 if (!ts) { 239 ts = new TimeSlot; 240 schedule(ts, tick); 241 } |
242 event->schedule(ts->events, tick); |
243 } 244 245 // For descheduling delayed/timed notifications/timeouts. 246 void 247 deschedule(ScEvent *event) 248 { |
249 ScEvents *on = event->scheduledOn(); 250 251 if (on == &deltas) { 252 event->deschedule(); 253 return; |
254 } 255 256 // Timed notification/timeout. 257 auto tsit = timeSlots.find(event->when()); 258 panic_if(tsit == timeSlots.end(), 259 "Descheduling event at time with no events."); 260 TimeSlot *ts = tsit->second; 261 ScEvents &events = ts->events; |
262 assert(on == &events); |
263 event->deschedule(); 264 265 // If no more events are happening at this time slot, get rid of it. 266 if (events.empty()) { 267 deschedule(ts); 268 timeSlots.erase(tsit); 269 } 270 } --- 145 unchanged lines hidden (view full) --- 416 std::map<::Event *, Tick> eventsToSchedule; 417}; 418 419extern Scheduler scheduler; 420 421inline void 422Scheduler::TimeSlot::process() 423{ |
424 while (!events.empty()) 425 events.front()->run(); |
426 scheduler.completeTimeSlot(this); 427} 428 429} // namespace sc_gem5 430 431#endif // __SYSTEMC_CORE_SCHEDULER_H__ |