eventq.hh (9159:8adc048515b8) eventq.hh (9356:b279bad40aa3)
1/*
2 * Copyright (c) 2000-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

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

39#include <algorithm>
40#include <cassert>
41#include <climits>
42#include <iosfwd>
43#include <string>
44
45#include "base/flags.hh"
46#include "base/misc.hh"
1/*
2 * Copyright (c) 2000-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

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

39#include <algorithm>
40#include <cassert>
41#include <climits>
42#include <iosfwd>
43#include <string>
44
45#include "base/flags.hh"
46#include "base/misc.hh"
47#include "base/trace.hh"
48#include "base/types.hh"
49#include "debug/Event.hh"
50#include "sim/serialize.hh"
51
52class EventQueue; // forward declaration
53
54extern EventQueue mainEventQueue;
55

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

356/*
357 * Queue of events sorted in time order
358 */
359class EventQueue : public Serializable
360{
361 private:
362 std::string objName;
363 Event *head;
47#include "base/types.hh"
48#include "debug/Event.hh"
49#include "sim/serialize.hh"
50
51class EventQueue; // forward declaration
52
53extern EventQueue mainEventQueue;
54

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

355/*
356 * Queue of events sorted in time order
357 */
358class EventQueue : public Serializable
359{
360 private:
361 std::string objName;
362 Event *head;
363 Tick _curTick;
364
365 void insert(Event *event);
366 void remove(Event *event);
367
368 EventQueue(const EventQueue &);
369 const EventQueue &operator=(const EventQueue &);
370
371 public:
372 EventQueue(const std::string &n);
373
374 virtual const std::string name() const { return objName; }
375
376 // schedule the given event on this queue
377 void schedule(Event *event, Tick when);
378 void deschedule(Event *event);
379 void reschedule(Event *event, Tick when, bool always = false);
380
381 Tick nextTick() const { return head->when(); }
364
365 void insert(Event *event);
366 void remove(Event *event);
367
368 EventQueue(const EventQueue &);
369 const EventQueue &operator=(const EventQueue &);
370
371 public:
372 EventQueue(const std::string &n);
373
374 virtual const std::string name() const { return objName; }
375
376 // schedule the given event on this queue
377 void schedule(Event *event, Tick when);
378 void deschedule(Event *event);
379 void reschedule(Event *event, Tick when, bool always = false);
380
381 Tick nextTick() const { return head->when(); }
382 void setCurTick(Tick newVal) { _curTick = newVal; }
383 Tick getCurTick() { return _curTick; }
384
382 Event *serviceOne();
383
384 // process all events up to the given timestamp. we inline a
385 // quick test to see if there are any events to process; if so,
386 // call the internal out-of-line version to process them all.
387 void
388 serviceEvents(Tick when)
389 {
390 while (!empty()) {
391 if (nextTick() > when)
392 break;
393
394 /**
395 * @todo this assert is a good bug catcher. I need to
396 * make it true again.
397 */
398 //assert(head->when() >= when && "event scheduled in the past");
399 serviceOne();
400 }
385 Event *serviceOne();
386
387 // process all events up to the given timestamp. we inline a
388 // quick test to see if there are any events to process; if so,
389 // call the internal out-of-line version to process them all.
390 void
391 serviceEvents(Tick when)
392 {
393 while (!empty()) {
394 if (nextTick() > when)
395 break;
396
397 /**
398 * @todo this assert is a good bug catcher. I need to
399 * make it true again.
400 */
401 //assert(head->when() >= when && "event scheduled in the past");
402 serviceOne();
403 }
404
405 setCurTick(when);
401 }
402
403 // return true if no events are queued
404 bool empty() const { return head == NULL; }
405
406 void dump() const;
407
408 bool debugVerify() const;

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

471 eventq->deschedule(event);
472 }
473
474 void
475 reschedule(Event *event, Tick when, bool always = false)
476 {
477 eventq->reschedule(event, when, always);
478 }
406 }
407
408 // return true if no events are queued
409 bool empty() const { return head == NULL; }
410
411 void dump() const;
412
413 bool debugVerify() const;

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

476 eventq->deschedule(event);
477 }
478
479 void
480 reschedule(Event *event, Tick when, bool always = false)
481 {
482 eventq->reschedule(event, when, always);
483 }
484
485 void setCurTick(Tick newVal) { eventq->setCurTick(newVal); }
479};
480
486};
487
481inline void
482EventQueue::schedule(Event *event, Tick when)
483{
484 assert(when >= curTick());
485 assert(!event->scheduled());
486 assert(event->initialized());
487
488 event->setWhen(when, this);
489 insert(event);
490 event->flags.set(Event::Scheduled);
491 if (this == &mainEventQueue)
492 event->flags.set(Event::IsMainQueue);
493 else
494 event->flags.clear(Event::IsMainQueue);
495
496 if (DTRACE(Event))
497 event->trace("scheduled");
498}
499
500inline void
501EventQueue::deschedule(Event *event)
502{
503 assert(event->scheduled());
504 assert(event->initialized());
505
506 remove(event);
507
508 event->flags.clear(Event::Squashed);
509 event->flags.clear(Event::Scheduled);
510
511 if (DTRACE(Event))
512 event->trace("descheduled");
513
514 if (event->flags.isSet(Event::AutoDelete))
515 delete event;
516}
517
518inline void
519EventQueue::reschedule(Event *event, Tick when, bool always)
520{
521 assert(when >= curTick());
522 assert(always || event->scheduled());
523 assert(event->initialized());
524
525 if (event->scheduled())
526 remove(event);
527
528 event->setWhen(when, this);
529 insert(event);
530 event->flags.clear(Event::Squashed);
531 event->flags.set(Event::Scheduled);
532 if (this == &mainEventQueue)
533 event->flags.set(Event::IsMainQueue);
534 else
535 event->flags.clear(Event::IsMainQueue);
536
537 if (DTRACE(Event))
538 event->trace("rescheduled");
539}
540
541template <class T, void (T::* F)()>
542void
543DelayFunction(EventQueue *eventq, Tick when, T *object)
544{
545 class DelayEvent : public Event
546 {
547 private:
548 T *object;

--- 46 unchanged lines hidden ---
488template <class T, void (T::* F)()>
489void
490DelayFunction(EventQueue *eventq, Tick when, T *object)
491{
492 class DelayEvent : public Event
493 {
494 private:
495 T *object;

--- 46 unchanged lines hidden ---