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.
This commit is contained in:
Josef Söntgen 2013-10-29 17:15:10 +01:00 committed by Norman Feske
parent 4efd664619
commit 7ac23a2419

View File

@ -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);
}