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; // 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 |
81 |
82 bool 83 initialized() const 84 { 85 return this && (flags & InitMask) == Initialized; 86 } 87 |
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 { |
154 assert(_flags.noneSet(~PublicRead)); |
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) |
250 : nextBin(NULL), nextInBin(NULL), _priority(p), flags(Initialized) |
251 { 252#ifndef NDEBUG 253 instance = ++instanceCounter; 254 queue = NULL; 255#endif 256#ifdef EVENTQ_DEBUG |
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()); |
485 assert(event->initialized()); |
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()); |
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()); |
522 assert(event->initialized()); |
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 --- |