Deleted Added
sdiff udiff text old ( 5501:b1beee9351a4 ) new ( 5502:f0f8a3ee5aad )
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;

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

69 *
70 * Caution, the order of members is chosen to maximize data packing.
71 */
72class Event : public Serializable, public FastAlloc
73{
74 friend class EventQueue;
75
76 private:
77 Event *next;
78
79 /// queue to which this event belongs (though it may or may not be
80 /// scheduled on this queue yet)
81 EventQueue *_queue;
82
83 Tick _when; //!< timestamp when event should be processed
84 short _priority; //!< event priority
85 short _flags;
86

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

94 /// debugging.
95 Counter instance;
96#endif
97
98#ifdef DEBUG_EVENTQ
99 Tick whenCreated; //!< time created
100 Tick whenScheduled; //!< time scheduled
101#endif
102 protected:
103 enum Flags {
104 None = 0x0,
105 Squashed = 0x1,
106 Scheduled = 0x2,
107 AutoDelete = 0x4,
108 AutoSerialize = 0x8,
109 IsExitEvent = 0x10
110 };

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

176 Maximum_Pri = SHRT_MAX
177 };
178
179 /*
180 * Event constructor
181 * @param queue that the event gets scheduled on
182 */
183 Event(EventQueue *q, Priority p = Default_Pri)
184 : next(NULL), _queue(q), _priority(p), _flags(None)
185 {
186#ifndef NDEBUG
187 instance = ++instanceCounter;
188#endif
189#ifdef EVENTQ_DEBUG
190 whenCreated = curTick;
191 whenScheduled = 0;
192#endif

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

338 // constructor
339 EventQueue(const std::string &n)
340 : objName(n), head(NULL)
341 {}
342
343 virtual const std::string name() const { return objName; }
344
345 // schedule the given event on this queue
346 void schedule(Event *ev);
347 void deschedule(Event *ev);
348 void reschedule(Event *ev);
349
350 Tick nextTick() const { return head->when(); }
351 Event *serviceOne();
352
353 // process all events up to the given timestamp. we inline a
354 // quick test to see if there are any events to process; if so,
355 // call the internal out-of-line version to process them all.
356 void

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

374
375 // return true if no events are queued
376 bool empty() const { return head == NULL; }
377
378 void dump() const;
379
380 Tick nextEventTime() { return empty() ? curTick : head->when(); }
381
382 virtual void serialize(std::ostream &os);
383 virtual void unserialize(Checkpoint *cp, const std::string &section);
384};
385
386
387//////////////////////
388//
389// inline functions
390//
391// can't put these inside declaration due to circular dependence
392// between Event and EventQueue classes.
393//
394//////////////////////
395
396// schedule at specified time (place on event queue specified via
397// constructor)
398inline void
399Event::schedule(Tick t)
400{
401 assert(!scheduled());
402 assert(t >= curTick);
403
404 setFlags(Scheduled);
405#ifdef DEBUG_EVENTQ
406 whenScheduled = curTick;
407#endif
408 _when = t;
409 _queue->schedule(this);
410}
411
412inline void
413Event::deschedule()
414{
415 assert(scheduled());
416
417 clearFlags(Squashed);
418 clearFlags(Scheduled);
419 _queue->deschedule(this);
420}
421
422inline void
423Event::reschedule(Tick t, bool always)
424{
425 assert(scheduled() || always);
426 assert(t >= curTick);
427
428#ifdef DEBUG_EVENTQ
429 whenScheduled = curTick;
430#endif
431 _when = t;
432
433 if (scheduled()) {
434 clearFlags(Squashed);
435 _queue->reschedule(this);
436 } else {
437 setFlags(Scheduled);
438 _queue->schedule(this);
439 }
440}
441
442inline void
443EventQueue::schedule(Event *event)
444{
445 insert(event);
446 if (DTRACE(Event))
447 event->trace("scheduled");
448}
449
450inline void
451EventQueue::deschedule(Event *event)
452{
453 remove(event);
454 if (DTRACE(Event))
455 event->trace("descheduled");
456
457 if (event->getFlags(Event::AutoDelete))
458 delete event;
459}
460
461inline void
462EventQueue::reschedule(Event *event)
463{
464 remove(event);
465 insert(event);
466 if (DTRACE(Event))
467 event->trace("rescheduled");
468}
469
470#endif // __SIM_EVENTQ_HH__