This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
SDL_systimer.c
104 lines (86 loc) · 2.12 KB
1
2
/*
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997-2006 Sam Lantinga
4
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
9
10
11
12
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
13
Lesser General Public License for more details.
14
15
16
17
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
18
19
Sam Lantinga
20
slouken@libsdl.org
21
*/
22
#include "SDL_config.h"
23
24
25
#ifdef SDL_TIMER_BEOS
26
27
28
29
#include <be/kernel/OS.h>
#include "SDL_thread.h"
#include "SDL_timer.h"
30
#include "../SDL_timer_c.h"
31
32
33
static bigtime_t start;
34
35
void
SDL_StartTicks(void)
36
{
37
38
/* Set first ticks value */
start = system_time();
39
40
}
41
42
Uint32
SDL_GetTicks(void)
43
{
44
return ((system_time() - start) / 1000);
45
46
}
47
48
void
SDL_Delay(Uint32 ms)
49
{
50
snooze(ms * 1000);
51
52
53
54
55
56
}
/* Data to handle a single periodic alarm */
static int timer_alive = 0;
static SDL_Thread *timer = NULL;
57
58
static int
RunTimer(void *unused)
59
{
60
61
62
63
64
65
66
while (timer_alive) {
if (SDL_timer_running) {
SDL_ThreadedTimerCheck();
}
SDL_Delay(10);
}
return (0);
67
68
69
}
/* This is only called if the event thread is not running */
70
71
int
SDL_SYS_TimerInit(void)
72
{
73
74
75
76
77
timer_alive = 1;
timer = SDL_CreateThread(RunTimer, NULL);
if (timer == NULL)
return (-1);
return (SDL_SetTimerThreaded(1));
78
79
}
80
81
void
SDL_SYS_TimerQuit(void)
82
{
83
84
85
86
87
timer_alive = 0;
if (timer) {
SDL_WaitThread(timer, NULL);
timer = NULL;
}
88
89
}
90
91
int
SDL_SYS_StartTimer(void)
92
{
93
94
SDL_SetError("Internal logic error: BeOS uses threaded timer");
return (-1);
95
96
}
97
98
void
SDL_SYS_StopTimer(void)
99
{
100
return;
101
}
102
103
#endif /* SDL_TIMER_BEOS */
104
/* vi: set ts=4 sw=4 expandtab: */