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; --- 63 unchanged lines hidden (view full) --- 72 static const FlagsType PublicRead = 0x003f; 73 static const FlagsType PublicWrite = 0x001d; 74 static const FlagsType Squashed = 0x0001; 75 static const FlagsType Scheduled = 0x0002; 76 static const FlagsType AutoDelete = 0x0004; 77 static const FlagsType AutoSerialize = 0x0008; 78 static const FlagsType IsExitEvent = 0x0010; 79 static const FlagsType IsMainQueue = 0x0020; |
80#ifdef EVENTQ_DEBUG 81 static const FlagsType Initialized = 0xf000; 82#endif |
83 84 private: 85 // The event queue is now a linked list of linked lists. The 86 // 'nextBin' pointer is to find the bin, where a bin is defined as 87 // when+priority. All events in the same bin will be stored in a 88 // second linked list (a stack) maintained by the 'nextInBin' 89 // pointer. The list will be accessed in LIFO order. The end 90 // result is that the insert/removal in 'nextBin' is --- 152 unchanged lines hidden (view full) --- 243 Event(Priority p = Default_Pri) 244 : nextBin(NULL), nextInBin(NULL), _priority(p) 245 { 246#ifndef NDEBUG 247 instance = ++instanceCounter; 248 queue = NULL; 249#endif 250#ifdef EVENTQ_DEBUG |
251 flags.set(Initialized); |
252 whenCreated = curTick; 253 whenScheduled = 0; 254#endif 255 } 256 257 virtual ~Event(); 258 virtual const std::string name() const; 259 --- 208 unchanged lines hidden (view full) --- 468 void process() { (object->*F)(); } 469}; 470 471inline void 472EventQueue::schedule(Event *event, Tick when) 473{ 474 assert(when >= curTick); 475 assert(!event->scheduled()); |
476#ifdef EVENTQ_DEBUG 477 assert((event->flags & Event::Initialized) == Event::Initialized); 478#endif |
479 480 event->setWhen(when, this); 481 insert(event); 482 event->flags.set(Event::Scheduled); 483 if (this == &mainEventQueue) 484 event->flags.set(Event::IsMainQueue); 485 else 486 event->flags.clear(Event::IsMainQueue); 487 488 if (DTRACE(Event)) 489 event->trace("scheduled"); 490} 491 492inline void 493EventQueue::deschedule(Event *event) 494{ 495 assert(event->scheduled()); |
496#ifdef EVENTQ_DEBUG 497 assert((event->flags & Event::Initialized) == Event::Initialized); 498#endif |
499 500 remove(event); 501 502 event->flags.clear(Event::Squashed); 503 event->flags.clear(Event::Scheduled); 504 505 if (event->flags.isSet(Event::AutoDelete)) 506 delete event; 507 508 if (DTRACE(Event)) 509 event->trace("descheduled"); 510} 511 512inline void 513EventQueue::reschedule(Event *event, Tick when, bool always) 514{ 515 assert(when >= curTick); 516 assert(always || event->scheduled()); |
517#ifdef EVENTQ_DEBUG 518 assert((event->flags & Event::Initialized) == Event::Initialized); 519#endif |
520 521 if (event->scheduled()) 522 remove(event); 523 524 event->setWhen(when, this); 525 insert(event); 526 event->flags.clear(Event::Squashed); 527 event->flags.set(Event::Scheduled); --- 50 unchanged lines hidden --- |