Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
100 lines (83 loc) · 2.06 KB

SDL_systimer.c

File metadata and controls

100 lines (83 loc) · 2.06 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Jan 24, 2010
Jan 24, 2010
3
Copyright (C) 1997-2010 Sam Lantinga
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 14, 2006
Apr 14, 2006
24
25
#if defined(SDL_TIMER_DUMMY) || defined(SDL_TIMERS_DISABLED)
Mar 8, 2006
Mar 8, 2006
26
27
28
#include "SDL_timer.h"
#include "../SDL_timer_c.h"
Jul 10, 2006
Jul 10, 2006
29
30
void
SDL_StartTicks(void)
Jul 10, 2006
Jul 10, 2006
34
35
Uint32
SDL_GetTicks(void)
Jul 10, 2006
Jul 10, 2006
37
38
SDL_Unsupported();
return 0;
Jul 10, 2006
Jul 10, 2006
41
42
void
SDL_Delay(Uint32 ms)
Jul 10, 2006
Jul 10, 2006
44
SDL_Unsupported();
45
46
47
48
49
50
51
52
}
#include "SDL_thread.h"
/* Data to handle a single periodic alarm */
static int timer_alive = 0;
static SDL_Thread *timer = NULL;
Jul 10, 2006
Jul 10, 2006
53
54
static int
RunTimer(void *unused)
Jul 10, 2006
Jul 10, 2006
56
57
58
59
60
61
62
while (timer_alive) {
if (SDL_timer_running) {
SDL_ThreadedTimerCheck();
}
SDL_Delay(1);
}
return (0);
63
64
65
}
/* This is only called if the event thread is not running */
Jul 10, 2006
Jul 10, 2006
66
67
int
SDL_SYS_TimerInit(void)
Jul 10, 2006
Jul 10, 2006
69
70
71
72
73
timer_alive = 1;
timer = SDL_CreateThread(RunTimer, NULL);
if (timer == NULL)
return (-1);
return (SDL_SetTimerThreaded(1));
Jul 10, 2006
Jul 10, 2006
76
77
void
SDL_SYS_TimerQuit(void)
Jul 10, 2006
Jul 10, 2006
79
80
81
82
83
timer_alive = 0;
if (timer) {
SDL_WaitThread(timer, NULL);
timer = NULL;
}
Jul 10, 2006
Jul 10, 2006
86
87
int
SDL_SYS_StartTimer(void)
Jul 10, 2006
Jul 10, 2006
89
90
SDL_SetError("Internal logic error: threaded timer in use");
return (-1);
Jul 10, 2006
Jul 10, 2006
93
94
void
SDL_SYS_StopTimer(void)
Jul 10, 2006
Jul 10, 2006
96
return;
Apr 14, 2006
Apr 14, 2006
98
99
#endif /* SDL_TIMER_DUMMY || SDL_TIMERS_DISABLED */
Jul 10, 2006
Jul 10, 2006
100
/* vi: set ts=4 sw=4 expandtab: */