src/timer/dummy/SDL_systimer.c
author Sam Lantinga
Wed, 08 Mar 2006 08:30:17 +0000
changeset 1484 b2b476a4a73c
parent 1402 d910939febfa
child 1635 92947e3a18db
permissions -rw-r--r--
Added documentation on how to build a completely useless SDL library. :)
slouken@1361
     1
/*
slouken@1361
     2
    SDL - Simple DirectMedia Layer
slouken@1361
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@1361
     4
slouken@1361
     5
    This library is free software; you can redistribute it and/or
slouken@1361
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1361
     7
    License as published by the Free Software Foundation; either
slouken@1361
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1361
     9
slouken@1361
    10
    This library is distributed in the hope that it will be useful,
slouken@1361
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1361
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1361
    13
    Lesser General Public License for more details.
slouken@1361
    14
slouken@1361
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1361
    16
    License along with this library; if not, write to the Free Software
slouken@1361
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1361
    18
slouken@1361
    19
    Sam Lantinga
slouken@1361
    20
    slouken@libsdl.org
slouken@1361
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@1361
    23
slouken@1484
    24
#include "SDL_timer.h"
slouken@1484
    25
#include "../SDL_timer_c.h"
slouken@1484
    26
slouken@1361
    27
void SDL_StartTicks(void)
slouken@1361
    28
{
slouken@1361
    29
}
slouken@1361
    30
slouken@1361
    31
Uint32 SDL_GetTicks (void)
slouken@1361
    32
{
slouken@1361
    33
	SDL_Unsupported();
slouken@1361
    34
	return 0;
slouken@1361
    35
}
slouken@1361
    36
slouken@1361
    37
void SDL_Delay (Uint32 ms)
slouken@1361
    38
{
slouken@1361
    39
	SDL_Unsupported();
slouken@1361
    40
}
slouken@1361
    41
slouken@1361
    42
#include "SDL_thread.h"
slouken@1361
    43
slouken@1361
    44
/* Data to handle a single periodic alarm */
slouken@1361
    45
static int timer_alive = 0;
slouken@1361
    46
static SDL_Thread *timer = NULL;
slouken@1361
    47
slouken@1361
    48
static int RunTimer(void *unused)
slouken@1361
    49
{
slouken@1361
    50
	while ( timer_alive ) {
slouken@1361
    51
		if ( SDL_timer_running ) {
slouken@1361
    52
			SDL_ThreadedTimerCheck();
slouken@1361
    53
		}
slouken@1361
    54
		SDL_Delay(1);
slouken@1361
    55
	}
slouken@1361
    56
	return(0);
slouken@1361
    57
}
slouken@1361
    58
slouken@1361
    59
/* This is only called if the event thread is not running */
slouken@1361
    60
int SDL_SYS_TimerInit(void)
slouken@1361
    61
{
slouken@1361
    62
	timer_alive = 1;
slouken@1361
    63
	timer = SDL_CreateThread(RunTimer, NULL);
slouken@1361
    64
	if ( timer == NULL )
slouken@1361
    65
		return(-1);
slouken@1361
    66
	return(SDL_SetTimerThreaded(1));
slouken@1361
    67
}
slouken@1361
    68
slouken@1361
    69
void SDL_SYS_TimerQuit(void)
slouken@1361
    70
{
slouken@1361
    71
	timer_alive = 0;
slouken@1361
    72
	if ( timer ) {
slouken@1361
    73
		SDL_WaitThread(timer, NULL);
slouken@1361
    74
		timer = NULL;
slouken@1361
    75
	}
slouken@1361
    76
}
slouken@1361
    77
slouken@1361
    78
int SDL_SYS_StartTimer(void)
slouken@1361
    79
{
slouken@1361
    80
	SDL_SetError("Internal logic error: threaded timer in use");
slouken@1361
    81
	return(-1);
slouken@1361
    82
}
slouken@1361
    83
slouken@1361
    84
void SDL_SYS_StopTimer(void)
slouken@1361
    85
{
slouken@1361
    86
	return;
slouken@1361
    87
}