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#ifndef SWIG
315inline bool
316operator<(const Event &l, const Event &r)
317{
318 return l.when() < r.when() ||
319 (l.when() == r.when() && l.priority() < r.priority());
320}
321
322inline bool
323operator>(const Event &l, const Event &r)
324{
325 return l.when() > r.when() ||
326 (l.when() == r.when() && l.priority() > r.priority());
327}
328
329inline bool
330operator<=(const Event &l, const Event &r)
331{
332 return l.when() < r.when() ||
333 (l.when() == r.when() && l.priority() <= r.priority());
334}
335inline bool
336operator>=(const Event &l, const Event &r)
337{
338 return l.when() > r.when() ||
339 (l.when() == r.when() && l.priority() >= r.priority());
340}
341
342inline bool
343operator==(const Event &l, const Event &r)
344{
345 return l.when() == r.when() && l.priority() == r.priority();
346}
347
348inline bool
349operator!=(const Event &l, const Event &r)
350{
351 return l.when() != r.when() || l.priority() != r.priority();
352}
353#endif
354
355/*
356 * Queue of events sorted in time order
357 */
358class EventQueue : public Serializable
359{
360 private:
361 std::string objName;
362 Event *head;

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

466
467 void
468 reschedule(Event *event, Tick when, bool always = false)
469 {
470 eventq->reschedule(event, when, always);
471 }
472};
473
474inline void
475EventQueue::schedule(Event *event, Tick when)
476{
477 assert((UTick)when >= (UTick)curTick);
478 assert(!event->scheduled());
479#ifdef EVENTQ_DEBUG
480 assert((event->flags & Event::Initialized) == Event::Initialized);
481#endif

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

532 event->flags.set(Event::IsMainQueue);
533 else
534 event->flags.clear(Event::IsMainQueue);
535
536 if (DTRACE(Event))
537 event->trace("rescheduled");
538}
539
540template <class T, void (T::* F)()>
541void
542DelayFunction(EventQueue *eventq, Tick when, T *object)
543{
544 class DelayEvent : public Event
545 {
546 private:
547 T *object;
548
549 public:
550 DelayEvent(T *o)
551 : object(o)
552 { this->setFlags(AutoDelete); }
553 void process() { (object->*F)(); }
554 const char *description() const { return "delay"; }
555 };
556
557 eventq->schedule(new DelayEvent(object), when);
558}
559
560template <class T, void (T::* F)()>
561class EventWrapper : public Event
562{
563 private:
564 T *object;
565
566 public:
567 EventWrapper(T *obj, bool del = false, Priority p = Default_Pri)
568 : Event(p), object(obj)
569 {
570 if (del)
571 setFlags(AutoDelete);
572 }
573
574 void process() { (object->*F)(); }
575
576 const std::string
577 name() const
578 {
579 return object->name() + ".wrapped_event";
580 }
581
582 const char *description() const { return "EventWrapped"; }
583};
584#endif
585
586#endif // __SIM_EVENTQ_HH__