Ticket #3010: timer.diff
File timer.diff, 1.9 KB (added by , 18 years ago) |
---|
-
backends/timer/default/default-timer.cpp
29 29 struct TimerSlot { 30 30 Common::TimerManager::TimerProc callback; 31 31 void *refCon; 32 int32 interval; 33 int32 nextFireTime; 32 uint32 interval; // microseconds 33 uint32 nextFireTime; // milliseconds 34 uint32 microsecs; 34 35 35 36 TimerSlot *next; 36 37 }; … … 39 40 // The head points to a fake anchor TimerSlot; this common 40 41 // trick allows us to get rid of many special cases. 41 42 42 const int32 nextFireTime = newSlot->nextFireTime;43 const uint32 nextFireTime = newSlot->nextFireTime; 43 44 TimerSlot *slot = head; 44 45 newSlot->next = 0; 45 46 … … 80 81 void DefaultTimerManager::handler() { 81 82 Common::StackLock lock(_mutex); 82 83 83 const int32 curTime = g_system->getMillis() * 1000;84 const uint32 curTime = g_system->getMillis(); 84 85 85 86 // Repeat as long as there is a TimerSlot that is scheduled to fire. 86 87 TimerSlot *slot = _head->next; … … 92 93 // queue. Has to be done before the timer callback is invoked, in case 93 94 // the callback wants to remove itself. 94 95 assert(slot->interval > 0); 95 slot->nextFireTime += slot->interval; 96 slot->nextFireTime += (slot->interval / 1000); 97 slot->microsecs += (slot->interval % 1000); 98 if (slot->microsecs > 1000) { 99 slot->nextFireTime++; 100 slot->microsecs -= 1000; 101 } 96 102 insertPrioQueue(_head, slot); 97 103 98 104 // Invoke the timer callback … … 108 114 assert(interval > 0); 109 115 Common::StackLock lock(_mutex); 110 116 111 112 117 TimerSlot *slot = new TimerSlot; 113 118 slot->callback = callback; 114 119 slot->refCon = refCon; 115 120 slot->interval = interval; 116 slot->nextFireTime = g_system->getMillis() * 1000 + interval; 121 slot->nextFireTime = g_system->getMillis() + interval / 1000; 122 slot->microsecs = interval % 1000; 117 123 slot->next = 0; 118 124 119 125 insertPrioQueue(_head, slot);