Mercurial > sdl-ios-xcode
comparison src/timer/riscos/SDL_systimer.c @ 955:d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
From: "alan buckley"
Subject: Modification for RISC OS version of SDL
Ive attached a zip file with the changes to this email, it contains the
following:
The file sdldiff.txt is the output from cvs diff u. .
The directory thread/riscos contains all the new files to support threading.
Readme.riscos is a new readme file to add.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 17 Sep 2004 13:20:10 +0000 |
parents | b8d311d90021 |
children | 974ba6ae0fa3 |
comparison
equal
deleted
inserted
replaced
954:3acd16ea0180 | 955:d74fbf56f2f6 |
---|---|
34 | 34 |
35 #include "SDL_error.h" | 35 #include "SDL_error.h" |
36 #include "SDL_timer.h" | 36 #include "SDL_timer.h" |
37 #include "SDL_timer_c.h" | 37 #include "SDL_timer_c.h" |
38 | 38 |
39 #ifdef DISABLE_THREADS | |
39 /* Timer start/reset time */ | 40 /* Timer start/reset time */ |
40 static Uint32 timerStart; | 41 static Uint32 timerStart; |
41 /* Timer running function */ | 42 /* Timer running function */ |
42 void RISCOS_CheckTimer(); | 43 void RISCOS_CheckTimer(); |
44 #else | |
45 #include <pthread.h> | |
46 extern Uint32 riscos_main_thread; | |
47 extern int riscos_using_threads; | |
48 extern Uint32 SDL_ThreadID(); | |
49 extern Uint32 SDL_EventThreadID(void); | |
50 #endif | |
51 | |
43 | 52 |
44 extern void RISCOS_BackgroundTasks(void); | 53 extern void RISCOS_BackgroundTasks(void); |
45 | 54 |
46 /* The first ticks value of the application */ | 55 /* The first ticks value of the application */ |
47 clock_t start; | 56 clock_t start; |
73 | 82 |
74 #endif | 83 #endif |
75 | 84 |
76 } | 85 } |
77 | 86 |
78 extern void DRenderer_FillBuffers(); | |
79 | |
80 void SDL_Delay (Uint32 ms) | 87 void SDL_Delay (Uint32 ms) |
81 { | 88 { |
82 Uint32 now,then,elapsed; | 89 Uint32 now,then,elapsed; |
90 #ifndef DISABLE_THREADS | |
91 int is_event_thread; | |
92 if (riscos_using_threads) | |
93 { | |
94 is_event_thread = 0; | |
95 if (SDL_EventThreadID()) | |
96 { | |
97 if (SDL_EventThreadID() == SDL_ThreadID()) is_event_thread = 1; | |
98 } else if (SDL_ThreadID() == riscos_main_thread) is_event_thread = 1; | |
99 } else is_event_thread = 1; | |
100 #endif | |
101 | |
102 /*TODO: Next version of unixlib may allow us to use usleep here */ | |
103 /* for non event threads */ | |
83 | 104 |
84 /* Set the timeout interval - Linux only needs to do this once */ | 105 /* Set the timeout interval - Linux only needs to do this once */ |
85 then = SDL_GetTicks(); | 106 then = SDL_GetTicks(); |
86 | 107 |
87 do { | 108 do { |
88 /* Do background tasks required while sleeping as we are not multithreaded */ | 109 /* Do background tasks required while sleeping as we are not multithreaded */ |
110 #ifdef DISABLE_THREADS | |
89 RISCOS_BackgroundTasks(); | 111 RISCOS_BackgroundTasks(); |
112 #else | |
113 /* For threaded build only run background tasks in event thread */ | |
114 if (is_event_thread) RISCOS_BackgroundTasks(); | |
115 #endif | |
116 | |
90 /* Calculate the time interval left (in case of interrupt) */ | 117 /* Calculate the time interval left (in case of interrupt) */ |
91 now = SDL_GetTicks(); | 118 now = SDL_GetTicks(); |
92 elapsed = (now-then); | 119 elapsed = (now-then); |
93 then = now; | 120 then = now; |
94 if ( elapsed >= ms ) { | 121 if ( elapsed >= ms ) { |
95 break; | 122 break; |
96 } | 123 } |
97 ms -= elapsed; | 124 ms -= elapsed; |
125 #ifndef DISABLE_THREADS | |
126 /* Need to yield to let other threads have a go */ | |
127 if (riscos_using_threads) pthread_yield(); | |
128 #endif | |
98 | 129 |
99 } while ( 1 ); | 130 } while ( 1 ); |
100 } | 131 } |
132 | |
133 #ifdef DISABLE_THREADS | |
134 | |
135 /* Non-threaded version of timer */ | |
101 | 136 |
102 int SDL_SYS_TimerInit(void) | 137 int SDL_SYS_TimerInit(void) |
103 { | 138 { |
104 return(0); | 139 return(0); |
105 } | 140 } |
142 } | 177 } |
143 } | 178 } |
144 if (SDL_alarm_interval) timerStart = SDL_GetTicks(); | 179 if (SDL_alarm_interval) timerStart = SDL_GetTicks(); |
145 } | 180 } |
146 } | 181 } |
182 | |
183 #else | |
184 | |
185 /* Threaded version of timer - based on code for linux */ | |
186 | |
187 #include "SDL_thread.h" | |
188 | |
189 /* Data to handle a single periodic alarm */ | |
190 static int timer_alive = 0; | |
191 static SDL_Thread *timer = NULL; | |
192 | |
193 static int RunTimer(void *unused) | |
194 { | |
195 while ( timer_alive ) { | |
196 if ( SDL_timer_running ) { | |
197 SDL_ThreadedTimerCheck(); | |
198 } | |
199 SDL_Delay(1); | |
200 } | |
201 return(0); | |
202 } | |
203 | |
204 /* This is only called if the event thread is not running */ | |
205 int SDL_SYS_TimerInit(void) | |
206 { | |
207 timer_alive = 1; | |
208 timer = SDL_CreateThread(RunTimer, NULL); | |
209 if ( timer == NULL ) | |
210 return(-1); | |
211 return(SDL_SetTimerThreaded(1)); | |
212 } | |
213 | |
214 void SDL_SYS_TimerQuit(void) | |
215 { | |
216 timer_alive = 0; | |
217 if ( timer ) { | |
218 SDL_WaitThread(timer, NULL); | |
219 timer = NULL; | |
220 } | |
221 } | |
222 | |
223 int SDL_SYS_StartTimer(void) | |
224 { | |
225 SDL_SetError("Internal logic error: RISCOS uses threaded timer"); | |
226 return(-1); | |
227 } | |
228 | |
229 void SDL_SYS_StopTimer(void) | |
230 { | |
231 return; | |
232 } | |
233 | |
234 #endif /* DISABLE_THREADS */ |