eventq.hh (7058:5c7416199efd) | eventq.hh (7059:4fb4eeb5f412) |
---|---|
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; --- 54 unchanged lines hidden (view full) --- 63class Event : public Serializable, public FastAlloc 64{ 65 friend class EventQueue; 66 67 protected: 68 typedef short FlagsType; 69 typedef ::Flags<FlagsType> Flags; 70 | 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; --- 54 unchanged lines hidden (view full) --- 63class Event : public Serializable, public FastAlloc 64{ 65 friend class EventQueue; 66 67 protected: 68 typedef short FlagsType; 69 typedef ::Flags<FlagsType> Flags; 70 |
71 static const FlagsType PublicRead = 0x003f; 72 static const FlagsType PublicWrite = 0x001d; 73 static const FlagsType Squashed = 0x0001; 74 static const FlagsType Scheduled = 0x0002; 75 static const FlagsType AutoDelete = 0x0004; 76 static const FlagsType AutoSerialize = 0x0008; 77 static const FlagsType IsExitEvent = 0x0010; 78 static const FlagsType IsMainQueue = 0x0020; 79#ifdef EVENTQ_DEBUG 80 static const FlagsType Initialized = 0xf000; 81#endif | 71 static const FlagsType PublicRead = 0x003f; // public readable flags 72 static const FlagsType PublicWrite = 0x001d; // public writable flags 73 static const FlagsType Squashed = 0x0001; // has been squashed 74 static const FlagsType Scheduled = 0x0002; // has been scheduled 75 static const FlagsType AutoDelete = 0x0004; // delete after dispatch 76 static const FlagsType AutoSerialize = 0x0008; // must be serialized 77 static const FlagsType IsExitEvent = 0x0010; // special exit event 78 static const FlagsType IsMainQueue = 0x0020; // on main event queue 79 static const FlagsType Initialized = 0x7a40; // somewhat random bits 80 static const FlagsType InitMask = 0xffc0; // mask for init bits |
82 | 81 |
82 bool 83 initialized() const 84 { 85 return this && (flags & InitMask) == Initialized; 86 } 87 |
|
83 public: 84 typedef int8_t Priority; 85 86 private: 87 // The event queue is now a linked list of linked lists. The 88 // 'nextBin' pointer is to find the bin, where a bin is defined as 89 // when+priority. All events in the same bin will be stored in a 90 // second linked list (a stack) maintained by the 'nextInBin' --- 50 unchanged lines hidden (view full) --- 141 getFlags() const 142 { 143 return flags & PublicRead; 144 } 145 146 Flags 147 getFlags(Flags _flags) const 148 { | 88 public: 89 typedef int8_t Priority; 90 91 private: 92 // The event queue is now a linked list of linked lists. The 93 // 'nextBin' pointer is to find the bin, where a bin is defined as 94 // when+priority. All events in the same bin will be stored in a 95 // second linked list (a stack) maintained by the 'nextInBin' --- 50 unchanged lines hidden (view full) --- 146 getFlags() const 147 { 148 return flags & PublicRead; 149 } 150 151 Flags 152 getFlags(Flags _flags) const 153 { |
149 assert(flags.noneSet(~PublicRead)); | 154 assert(_flags.noneSet(~PublicRead)); |
150 return flags.isSet(_flags); 151 } 152 153 Flags 154 allFlags(Flags _flags) const 155 { 156 assert(_flags.noneSet(~PublicRead)); 157 return flags.allSet(_flags); --- 79 unchanged lines hidden (view full) --- 237 /// Maximum priority 238 static const Priority Maximum_Pri = SCHAR_MAX; 239 240 /* 241 * Event constructor 242 * @param queue that the event gets scheduled on 243 */ 244 Event(Priority p = Default_Pri) | 155 return flags.isSet(_flags); 156 } 157 158 Flags 159 allFlags(Flags _flags) const 160 { 161 assert(_flags.noneSet(~PublicRead)); 162 return flags.allSet(_flags); --- 79 unchanged lines hidden (view full) --- 242 /// Maximum priority 243 static const Priority Maximum_Pri = SCHAR_MAX; 244 245 /* 246 * Event constructor 247 * @param queue that the event gets scheduled on 248 */ 249 Event(Priority p = Default_Pri) |
245 : nextBin(NULL), nextInBin(NULL), _priority(p) | 250 : nextBin(NULL), nextInBin(NULL), _priority(p), flags(Initialized) |
246 { 247#ifndef NDEBUG 248 instance = ++instanceCounter; 249 queue = NULL; 250#endif 251#ifdef EVENTQ_DEBUG | 251 { 252#ifndef NDEBUG 253 instance = ++instanceCounter; 254 queue = NULL; 255#endif 256#ifdef EVENTQ_DEBUG |
252 flags.set(Initialized); | |
253 whenCreated = curTick; 254 whenScheduled = 0; 255#endif 256 } 257 258 virtual ~Event(); 259 virtual const std::string name() const; 260 --- 212 unchanged lines hidden (view full) --- 473 } 474}; 475 476inline void 477EventQueue::schedule(Event *event, Tick when) 478{ 479 assert((UTick)when >= (UTick)curTick); 480 assert(!event->scheduled()); | 257 whenCreated = curTick; 258 whenScheduled = 0; 259#endif 260 } 261 262 virtual ~Event(); 263 virtual const std::string name() const; 264 --- 212 unchanged lines hidden (view full) --- 477 } 478}; 479 480inline void 481EventQueue::schedule(Event *event, Tick when) 482{ 483 assert((UTick)when >= (UTick)curTick); 484 assert(!event->scheduled()); |
481#ifdef EVENTQ_DEBUG 482 assert((event->flags & Event::Initialized) == Event::Initialized); 483#endif | 485 assert(event->initialized()); |
484 485 event->setWhen(when, this); 486 insert(event); 487 event->flags.set(Event::Scheduled); 488 if (this == &mainEventQueue) 489 event->flags.set(Event::IsMainQueue); 490 else 491 event->flags.clear(Event::IsMainQueue); 492 493 if (DTRACE(Event)) 494 event->trace("scheduled"); 495} 496 497inline void 498EventQueue::deschedule(Event *event) 499{ 500 assert(event->scheduled()); | 486 487 event->setWhen(when, this); 488 insert(event); 489 event->flags.set(Event::Scheduled); 490 if (this == &mainEventQueue) 491 event->flags.set(Event::IsMainQueue); 492 else 493 event->flags.clear(Event::IsMainQueue); 494 495 if (DTRACE(Event)) 496 event->trace("scheduled"); 497} 498 499inline void 500EventQueue::deschedule(Event *event) 501{ 502 assert(event->scheduled()); |
501#ifdef EVENTQ_DEBUG 502 assert((event->flags & Event::Initialized) == Event::Initialized); 503#endif | 503 assert(event->initialized()); |
504 505 remove(event); 506 507 event->flags.clear(Event::Squashed); 508 event->flags.clear(Event::Scheduled); 509 510 if (event->flags.isSet(Event::AutoDelete)) 511 delete event; 512 513 if (DTRACE(Event)) 514 event->trace("descheduled"); 515} 516 517inline void 518EventQueue::reschedule(Event *event, Tick when, bool always) 519{ 520 assert(when >= curTick); 521 assert(always || event->scheduled()); | 504 505 remove(event); 506 507 event->flags.clear(Event::Squashed); 508 event->flags.clear(Event::Scheduled); 509 510 if (event->flags.isSet(Event::AutoDelete)) 511 delete event; 512 513 if (DTRACE(Event)) 514 event->trace("descheduled"); 515} 516 517inline void 518EventQueue::reschedule(Event *event, Tick when, bool always) 519{ 520 assert(when >= curTick); 521 assert(always || event->scheduled()); |
522#ifdef EVENTQ_DEBUG 523 assert((event->flags & Event::Initialized) == Event::Initialized); 524#endif | 522 assert(event->initialized()); |
525 526 if (event->scheduled()) 527 remove(event); 528 529 event->setWhen(when, this); 530 insert(event); 531 event->flags.clear(Event::Squashed); 532 event->flags.set(Event::Scheduled); --- 56 unchanged lines hidden --- | 523 524 if (event->scheduled()) 525 remove(event); 526 527 event->setWhen(when, this); 528 insert(event); 529 event->flags.clear(Event::Squashed); 530 event->flags.set(Event::Scheduled); --- 56 unchanged lines hidden --- |