Commit dcd48df0 authored by Sam Lantinga's avatar Sam Lantinga

Fixed bug in timer when the list of timers changed.

Fix contributed by Michael Bicha
parent c4bf458e
...@@ -113,8 +113,10 @@ SDL_ThreadedTimerCheck(void) ...@@ -113,8 +113,10 @@ SDL_ThreadedTimerCheck(void)
SDL_bool removed; SDL_bool removed;
SDL_mutexP(SDL_timer_mutex); SDL_mutexP(SDL_timer_mutex);
list_changed = SDL_FALSE;
now = SDL_GetTicks(); now = SDL_GetTicks();
do {
list_changed = SDL_FALSE;
for (prev = NULL, t = SDL_timers; t; t = next) { for (prev = NULL, t = SDL_timers; t; t = next) {
removed = SDL_FALSE; removed = SDL_FALSE;
ms = t->interval - SDL_TIMESLICE; ms = t->interval - SDL_TIMESLICE;
...@@ -128,17 +130,20 @@ SDL_ThreadedTimerCheck(void) ...@@ -128,17 +130,20 @@ SDL_ThreadedTimerCheck(void)
t->last_alarm = now; t->last_alarm = now;
} }
#ifdef DEBUG_TIMERS #ifdef DEBUG_TIMERS
printf("Executing timer %p (thread = %lu)\n", t, SDL_ThreadID()); printf("Executing timer %p (thread = %lu)\n",
t, SDL_ThreadID());
#endif #endif
timer = *t; timer = *t;
SDL_mutexV(SDL_timer_mutex); SDL_mutexV(SDL_timer_mutex);
ms = timer.cb(timer.interval, timer.param); ms = timer.cb(timer.interval, timer.param);
SDL_mutexP(SDL_timer_mutex); SDL_mutexP(SDL_timer_mutex);
if (list_changed) { if (list_changed) {
/* Abort, list of timers modified */ next = t->next;
/* FIXME: what if ms was changed? */ for (prev = SDL_timers; prev; prev = prev->next) {
if (prev->next == t)
break; break;
} }
}
if (ms != t->interval) { if (ms != t->interval) {
if (ms) { if (ms) {
t->interval = ROUND_RESOLUTION(ms); t->interval = ROUND_RESOLUTION(ms);
...@@ -157,12 +162,18 @@ SDL_ThreadedTimerCheck(void) ...@@ -157,12 +162,18 @@ SDL_ThreadedTimerCheck(void)
removed = SDL_TRUE; removed = SDL_TRUE;
} }
} }
if (list_changed) {
/* Abort, list of timers modified */
break;
}
} }
/* Don't update prev if the timer has disappeared */ /* Don't update prev if the timer has disappeared */
if (!removed) { if (!removed) {
prev = t; prev = t;
} }
} }
} while (list_changed);
SDL_mutexV(SDL_timer_mutex); SDL_mutexV(SDL_timer_mutex);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment