19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL - Simple DirectMedia Layer
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Copyright (C) 1997-2012 Sam Lantinga
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is free software; you can redistribute it and/or
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    modify it under the terms of the GNU Lesser General Public
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License as published by the Free Software Foundation; either
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    version 2.1 of the License, or (at your option) any later version.
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is distributed in the hope that it will be useful,
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    but WITHOUT ANY WARRANTY; without even the implied warranty of
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Lesser General Public License for more details.
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    You should have received a copy of the GNU Lesser General Public
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License along with this library; if not, write to the Free Software
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Sam Lantinga
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    slouken@libsdl.org
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h"
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(SDL_TIMER_DUMMY) || defined(SDL_TIMERS_DISABLED)
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_timer.h"
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../SDL_timer_c.h"
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_StartTicks(void)
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallUint32 SDL_GetTicks (void)
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_Unsupported();
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return 0;
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_Delay (Uint32 ms)
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_Unsupported();
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_thread.h"
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Data to handle a single periodic alarm */
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int timer_alive = 0;
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDL_Thread *timer = NULL;
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int RunTimer(void *unused)
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	while ( timer_alive ) {
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( SDL_timer_running ) {
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_ThreadedTimerCheck();
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_Delay(1);
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(0);
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* This is only called if the event thread is not running */
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_SYS_TimerInit(void)
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	timer_alive = 1;
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	timer = SDL_CreateThread(RunTimer, NULL);
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( timer == NULL )
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return(-1);
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(SDL_SetTimerThreaded(1));
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_SYS_TimerQuit(void)
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	timer_alive = 0;
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( timer ) {
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_WaitThread(timer, NULL);
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		timer = NULL;
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_SYS_StartTimer(void)
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_SetError("Internal logic error: threaded timer in use");
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(-1);
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_SYS_StopTimer(void)
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return;
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* SDL_TIMER_DUMMY || SDL_TIMERS_DISABLED */
92