Deleted Added
sdiff udiff text old ( 7004:b9e4f8a3fea7 ) new ( 7005:3d5c4acb6015 )
full compact
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;

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

306 }
307 };
308
309 virtual void serialize(std::ostream &os);
310 virtual void unserialize(Checkpoint *cp, const std::string &section);
311#endif
312};
313
314/*
315 * Queue of events sorted in time order
316 */
317class EventQueue : public Serializable
318{
319 private:
320 std::string objName;
321 Event *head;

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

425
426 void
427 reschedule(Event *event, Tick when, bool always = false)
428 {
429 eventq->reschedule(event, when, always);
430 }
431};
432
433template <class T, void (T::* F)()>
434void
435DelayFunction(EventQueue *eventq, Tick when, T *object)
436{
437 class DelayEvent : public Event
438 {
439 private:
440 T *object;
441
442 public:
443 DelayEvent(T *o)
444 : object(o)
445 { this->setFlags(AutoDelete); }
446 void process() { (object->*F)(); }
447 const char *description() const { return "delay"; }
448 };
449
450 eventq->schedule(new DelayEvent(object), when);
451}
452
453template <class T, void (T::* F)()>
454class EventWrapper : public Event
455{
456 private:
457 T *object;
458
459 public:
460 EventWrapper(T *obj, bool del = false, Priority p = Default_Pri)
461 : Event(p), object(obj)
462 {
463 if (del)
464 setFlags(AutoDelete);
465 }
466
467 void process() { (object->*F)(); }
468
469 const std::string
470 name() const
471 {
472 return object->name() + ".wrapped_event";
473 }
474
475 const char *description() const { return "EventWrapped"; }
476};
477
478inline void
479EventQueue::schedule(Event *event, Tick when)
480{
481 assert((UTick)when >= (UTick)curTick);
482 assert(!event->scheduled());
483#ifdef EVENTQ_DEBUG
484 assert((event->flags & Event::Initialized) == Event::Initialized);
485#endif

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

536 event->flags.set(Event::IsMainQueue);
537 else
538 event->flags.clear(Event::IsMainQueue);
539
540 if (DTRACE(Event))
541 event->trace("rescheduled");
542}
543
544inline bool
545operator<(const Event &l, const Event &r)
546{
547 return l.when() < r.when() ||
548 (l.when() == r.when() && l.priority() < r.priority());
549}
550
551inline bool
552operator>(const Event &l, const Event &r)
553{
554 return l.when() > r.when() ||
555 (l.when() == r.when() && l.priority() > r.priority());
556}
557
558inline bool
559operator<=(const Event &l, const Event &r)
560{
561 return l.when() < r.when() ||
562 (l.when() == r.when() && l.priority() <= r.priority());
563}
564inline bool
565operator>=(const Event &l, const Event &r)
566{
567 return l.when() > r.when() ||
568 (l.when() == r.when() && l.priority() >= r.priority());
569}
570
571inline bool
572operator==(const Event &l, const Event &r)
573{
574 return l.when() == r.when() && l.priority() == r.priority();
575}
576
577inline bool
578operator!=(const Event &l, const Event &r)
579{
580 return l.when() != r.when() || l.priority() != r.priority();
581}
582#endif
583
584#endif // __SIM_EVENTQ_HH__