genode/repos/libports/src/lib/sdl/timer/SDL_systimer.cc
Norman Feske ca971bbfd8 Move repositories to 'repos/' subdirectory
This patch changes the top-level directory layout as a preparatory
step for improving the tools for managing 3rd-party source codes.
The rationale is described in the issue referenced below.

Issue #1082
2014-05-14 16:08:00 +02:00

104 lines
1.5 KiB
C++

/*
* \brief Genode-specific timer backend
* \author Christian Prochaska
* \date 2012-03-13
*
* based on the dummy SDL timer
*/
/*
* Copyright (C) 2012-2013 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#include <timer_session/connection.h>
extern "C" {
#include <unistd.h>
#include "SDL_config.h"
#include "SDL_timer.h"
#include "SDL_timer_c.h"
static unsigned long start_ms = 0;
static Timer::Connection _timer;
void SDL_StartTicks(void)
{
start_ms = _timer.elapsed_ms();
}
Uint32 SDL_GetTicks (void)
{
return _timer.elapsed_ms() - start_ms;
}
void SDL_Delay (Uint32 ms)
{
_timer.msleep(ms);
}
#include "SDL_thread.h"
/* Data to handle a single periodic alarm */
static int timer_alive = 0;
static SDL_Thread *timer = NULL;
static int RunTimer(void *unused)
{
while ( timer_alive ) {
if ( SDL_timer_running ) {
SDL_ThreadedTimerCheck();
}
SDL_Delay(1);
}
return(0);
}
/* This is only called if the event thread is not running */
int SDL_SYS_TimerInit(void)
{
timer_alive = 1;
timer = SDL_CreateThread(RunTimer, NULL);
if ( timer == NULL )
return(-1);
return(SDL_SetTimerThreaded(1));
}
void SDL_SYS_TimerQuit(void)
{
timer_alive = 0;
if ( timer ) {
SDL_WaitThread(timer, NULL);
timer = NULL;
}
}
int SDL_SYS_StartTimer(void)
{
SDL_SetError("Internal logic error: threaded timer in use");
return(-1);
}
void SDL_SYS_StopTimer(void)
{
return;
}
}