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)
SDL_bool removed;
SDL_mutexP(SDL_timer_mutex);
list_changed = SDL_FALSE;
now = SDL_GetTicks();
do {
list_changed = SDL_FALSE;
for (prev = NULL, t = SDL_timers; t; t = next) {
removed = SDL_FALSE;
ms = t->interval - SDL_TIMESLICE;
......@@ -128,17 +130,20 @@ SDL_ThreadedTimerCheck(void)
t->last_alarm = now;
}
#ifdef DEBUG_TIMERS
printf("Executing timer %p (thread = %lu)\n", t, SDL_ThreadID());
printf("Executing timer %p (thread = %lu)\n",
t, SDL_ThreadID());
#endif
timer = *t;
SDL_mutexV(SDL_timer_mutex);
ms = timer.cb(timer.interval, timer.param);
SDL_mutexP(SDL_timer_mutex);
if (list_changed) {
/* Abort, list of timers modified */
/* FIXME: what if ms was changed? */
next = t->next;
for (prev = SDL_timers; prev; prev = prev->next) {
if (prev->next == t)
break;
}
}
if (ms != t->interval) {
if (ms) {
t->interval = ROUND_RESOLUTION(ms);
......@@ -157,12 +162,18 @@ SDL_ThreadedTimerCheck(void)
removed = SDL_TRUE;
}
}
if (list_changed) {
/* Abort, list of timers modified */
break;
}
}
/* Don't update prev if the timer has disappeared */
if (!removed) {
prev = t;
}
}
} while (list_changed);
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