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
void
35
SDL_StartTicks(void)
36
{
37
/* Set first ticks value */
38
start = system_time();
39
40
}
41
Uint32
42
SDL_GetTicks(void)
43
{
44
return ((system_time() - start) / 1000);
45
46
}
47
void
48
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
static int
58
RunTimer(void *unused)
59
{
60
61
while (timer_alive) {
if (SDL_timer_running) {
62
SDL_ThreadedTimerCheck();
63
}
64
SDL_Delay(10);
65
66
}
return (0);
67
68
69
}
/* This is only called if the event thread is not running */
70
int
71
SDL_SYS_TimerInit(void)
72
{
73
timer_alive = 1;
74
timer = SDL_CreateThread(RunTimer, NULL);
75
76
if (timer == NULL)
return (-1);
77
return (SDL_SetTimerThreaded(1));
78
79
}
80
void
81
SDL_SYS_TimerQuit(void)
82
{
83
84
timer_alive = 0;
if (timer) {
85
SDL_WaitThread(timer, NULL);
86
87
timer = NULL;
}
88
89
}
90
int
91
SDL_SYS_StartTimer(void)
92
{
93
SDL_SetError("Internal logic error: BeOS uses threaded timer");
94
return (-1);
95
96
}
97
void
98
SDL_SYS_StopTimer(void)
99
{
100
return;
101
}
102
103
#endif /* SDL_TIMER_BEOS */
104
/* vi: set ts=4 sw=4 expandtab: */