From 7ac23a241991c3b947b853c328f936d205e40981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= <josef.soentgen@genode-labs.com> Date: Tue, 29 Oct 2013 17:15:10 +0100 Subject: [PATCH] libports: use Timer_session as SDL's timer backend A timer session is now used instead of a jiffy counter. This way, libSDL can use a time source that is not bound to the granularity our libc's nanosleep implementation. Currently, the granularity of nanosleep is in the order of 10 milliseconds, which is far to coarse for the use of SDL-using applications such as DosBox. Fixes #934. --- libports/src/lib/sdl/timer/SDL_systimer.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libports/src/lib/sdl/timer/SDL_systimer.cc b/libports/src/lib/sdl/timer/SDL_systimer.cc index dd0a9d0c7b..fba0a1efb5 100644 --- a/libports/src/lib/sdl/timer/SDL_systimer.cc +++ b/libports/src/lib/sdl/timer/SDL_systimer.cc @@ -13,6 +13,8 @@ * under the terms of the GNU General Public License version 2. */ +#include <timer_session/connection.h> + extern "C" { #include <unistd.h> @@ -23,23 +25,26 @@ extern "C" { #include "SDL_timer_c.h" -static Uint32 jiffies = 0; +static unsigned long start_ms = 0; + +static Timer::Connection _timer; void SDL_StartTicks(void) { + start_ms = _timer.elapsed_ms(); } Uint32 SDL_GetTicks (void) { - return jiffies; + return _timer.elapsed_ms() - start_ms; } void SDL_Delay (Uint32 ms) { - usleep(ms*1000); + _timer.msleep(ms); } @@ -50,7 +55,6 @@ void SDL_Delay (Uint32 ms) static int timer_alive = 0; static SDL_Thread *timer = NULL; - static int RunTimer(void *unused) { while ( timer_alive ) { @@ -58,7 +62,6 @@ static int RunTimer(void *unused) SDL_ThreadedTimerCheck(); } SDL_Delay(1); - jiffies++; } return(0); }