Deleted Added
sdiff udiff text old ( 5768:ba6f2477d870 ) new ( 5769:e53bdd0e4bf1 )
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;

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

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

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

59 * process() member function.
60 *
61 * Caution, the order of members is chosen to maximize data packing.
62 */
63class Event : public Serializable, public FastAlloc
64{
65 friend class EventQueue;
66
67 private:
68 // The event queue is now a linked list of linked lists. The
69 // 'nextBin' pointer is to find the bin, where a bin is defined as
70 // when+priority. All events in the same bin will be stored in a
71 // second linked list (a stack) maintained by the 'nextInBin'
72 // pointer. The list will be accessed in LIFO order. The end
73 // result is that the insert/removal in 'nextBin' is
74 // linear/constant, and the lookup/removal in 'nextInBin' is
75 // constant/constant. Hopefully this is a significant improvement
76 // over the current fully linear insertion.
77 Event *nextBin;
78 Event *nextInBin;
79
80 static Event *insertBefore(Event *event, Event *curr);
81 static Event *removeItem(Event *event, Event *last);
82
83 Tick _when; //!< timestamp when event should be processed
84 short _priority; //!< event priority
85 short _flags;
86
87#ifndef NDEBUG
88 /// Global counter to generate unique IDs for Event instances
89 static Counter instanceCounter;
90
91 /// This event's unique ID. We can also use pointer values for
92 /// this but they're not consistent across runs making debugging
93 /// more difficult. Thus we use a global counter value when

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

112 queue = q;
113#endif
114#ifdef EVENTQ_DEBUG
115 whenScheduled = curTick;
116#endif
117 }
118
119 protected:
120 enum Flags {
121 None = 0x0,
122 Squashed = 0x1,
123 Scheduled = 0x2,
124 AutoDelete = 0x4,
125 AutoSerialize = 0x8,
126 IsExitEvent = 0x10,
127 IsMainQueue = 0x20
128 };
129
130 bool getFlags(Flags f) const { return (_flags & f) == f; }
131 void setFlags(Flags f) { _flags |= f; }
132 void clearFlags(Flags f) { _flags &= ~f; }
133
134 protected:
135 // This function isn't really useful if TRACING_ON is not defined
136 virtual void trace(const char *action); //!< trace event activity
137
138 public:
139 /// Event priorities, to provide tie-breakers for events scheduled
140 /// at the same cycle. Most events are scheduled at the default
141 /// priority; these values are used to control events that need to
142 /// be ordered within a cycle.

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

192 Maximum_Pri = SHRT_MAX
193 };
194
195 /*
196 * Event constructor
197 * @param queue that the event gets scheduled on
198 */
199 Event(Priority p = Default_Pri)
200 : nextBin(NULL), nextInBin(NULL), _priority(p), _flags(None)
201 {
202#ifndef NDEBUG
203 instance = ++instanceCounter;
204 queue = NULL;
205#endif
206#ifdef EVENTQ_DEBUG
207 whenCreated = curTick;
208 whenScheduled = 0;

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

229 * statically allocated event objects).
230 *
231 * If the AutoDestroy flag is set, the object is deleted once it
232 * is processed.
233 */
234 virtual void process() = 0;
235
236 /// Determine if the current event is scheduled
237 bool scheduled() const { return getFlags(Scheduled); }
238
239 /// Squash the current event
240 void squash() { setFlags(Squashed); }
241
242 /// Check whether the event is squashed
243 bool squashed() const { return getFlags(Squashed); }
244
245 /// See if this is a SimExitEvent (without resorting to RTTI)
246 bool isExitEvent() const { return getFlags(IsExitEvent); }
247
248 /// Get the time that the event is scheduled
249 Tick when() const { return _when; }
250
251 /// Get the event priority
252 int priority() const { return _priority; }
253
254#ifndef SWIG

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

393 class DelayEvent : public Event
394 {
395 private:
396 T *object;
397
398 public:
399 DelayEvent(T *o)
400 : object(o)
401 { setFlags(this->AutoDestroy); }
402 void process() { (object->*F)(); }
403 const char *description() const { return "delay"; }
404 };
405
406 eventq->schedule(new DelayEvent(object), when);
407}
408
409template <class T, void (T::* F)()>

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

426inline void
427EventQueue::schedule(Event *event, Tick when)
428{
429 assert(when >= curTick);
430 assert(!event->scheduled());
431
432 event->setWhen(when, this);
433 insert(event);
434 event->setFlags(Event::Scheduled);
435 if (this == &mainEventQueue)
436 event->setFlags(Event::IsMainQueue);
437 else
438 event->clearFlags(Event::IsMainQueue);
439
440 if (DTRACE(Event))
441 event->trace("scheduled");
442}
443
444inline void
445EventQueue::deschedule(Event *event)
446{
447 assert(event->scheduled());
448
449 remove(event);
450
451 event->clearFlags(Event::Squashed);
452 event->clearFlags(Event::Scheduled);
453
454 if (event->getFlags(Event::AutoDelete))
455 delete event;
456
457 if (DTRACE(Event))
458 event->trace("descheduled");
459}
460
461inline void
462EventQueue::reschedule(Event *event, Tick when, bool always)
463{
464 assert(when >= curTick);
465 assert(always || event->scheduled());
466
467 if (event->scheduled())
468 remove(event);
469
470 event->setWhen(when, this);
471 insert(event);
472 event->clearFlags(Event::Squashed);
473 event->setFlags(Event::Scheduled);
474 if (this == &mainEventQueue)
475 event->setFlags(Event::IsMainQueue);
476 else
477 event->clearFlags(Event::IsMainQueue);
478
479 if (DTRACE(Event))
480 event->trace("rescheduled");
481}
482
483inline bool
484operator<(const Event &l, const Event &r)
485{

--- 38 unchanged lines hidden ---