eventq.hh (7004:b9e4f8a3fea7) eventq.hh (7005:3d5c4acb6015)
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
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
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
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
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
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
544inline bool
545operator<(const Event &l, const Event &r)
540template <class T, void (T::* F)()>
541void
542DelayFunction(EventQueue *eventq, Tick when, T *object)
546{
543{
547 return l.when() < r.when() ||
548 (l.when() == r.when() && l.priority() < r.priority());
549}
544 class DelayEvent : public Event
545 {
546 private:
547 T *object;
550
548
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}
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 };
557
556
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());
557 eventq->schedule(new DelayEvent(object), when);
563}
558}
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
559
571inline bool
572operator==(const Event &l, const Event &r)
560template <class T, void (T::* F)()>
561class EventWrapper : public Event
573{
562{
574 return l.when() == r.when() && l.priority() == r.priority();
575}
563 private:
564 T *object;
576
565
577inline bool
578operator!=(const Event &l, const Event &r)
579{
580 return l.when() != r.when() || l.priority() != r.priority();
581}
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};
582#endif
583
584#endif // __SIM_EVENTQ_HH__
584#endif
585
586#endif // __SIM_EVENTQ_HH__