ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Windows/timer_windows.cpp
(Generate patch)

Comparing BasiliskII/src/Windows/timer_windows.cpp (file contents):
Revision 1.1 by gbeauche, 2004-11-28T17:54:05Z vs.
Revision 1.7 by gbeauche, 2006-05-01T06:14:08Z

# Line 1 | Line 1
1   /*
2   *  timer_windows.cpp - Time Manager emulation, Windows specific stuff
3   *
4 < *  Basilisk II (C) 1997-2004 Christian Bauer
4 > *  Basilisk II (C) 1997-2005 Christian Bauer
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 34 | Line 34
34   // Helper time functions
35   #define MSECS2TICKS(MSECS) (((uint64)(MSECS) * frequency) / 1000)
36   #define USECS2TICKS(USECS) (((uint64)(USECS) * frequency) / 1000000)
37 #define TICKS2MSECS(TICKS) (((uint64)(TICKS) * 1000) / frequency)
37   #define TICKS2USECS(TICKS) (((uint64)(TICKS) * 1000000) / frequency)
38  
39 + // From main_windows.cpp
40 + extern HANDLE emul_thread;
41 +
42   // Global variables
43   static uint32 frequency;                                // CPU frequency in Hz (< 4 GHz)
44   static tm_time_t mac_boot_ticks;
# Line 48 | Line 50 | static tm_time_t mac_now_diff;
50   *  Initialize native Windows timers
51   */
52  
53 < void SysTimerInit(void)
53 > void timer_init(void)
54   {
55          D(bug("SysTimerInit\n"));
56  
# Line 165 | Line 167 | int32 timer_host2mac_time(tm_time_t host
167          if (hosttime < 0)
168                  return 0;
169          else {
170 <                uint64 t = TICKS2MSECS(hosttime);
170 >                uint64 t = TICKS2USECS(hosttime);
171                  if (t > 0x7fffffff)
172                          return t / 1000;        // Time in milliseconds
173                  else
# Line 196 | Line 198 | void Delay_usec(uint32 usec)
198          // millisecond resolution anyway
199          Sleep(usec / 1000);
200   }
201 +
202 +
203 + /*
204 + *  Suspend emulator thread, virtual CPU in idle mode
205 + */
206 +
207 + struct idle_sentinel {
208 +        idle_sentinel();
209 +        ~idle_sentinel();
210 + };
211 + static idle_sentinel idle_sentinel;
212 +
213 + static int idle_sem_ok = -1;
214 + static HANDLE idle_sem = NULL;
215 +
216 + static HANDLE idle_lock = NULL;
217 + #define LOCK_IDLE WaitForSingleObject(idle_lock, INFINITE)
218 + #define UNLOCK_IDLE ReleaseMutex(idle_lock)
219 +
220 + idle_sentinel::idle_sentinel()
221 + {
222 +        idle_sem_ok = 1;
223 +        if ((idle_sem = CreateSemaphore(0, 0, 1, NULL)) == NULL)
224 +                idle_sem_ok = 0;
225 +        if ((idle_lock = CreateMutex(NULL, FALSE, NULL)) == NULL)
226 +                idle_sem_ok = 0;
227 + }
228 +
229 + idle_sentinel::~idle_sentinel()
230 + {
231 +        if (idle_lock) {
232 +                ReleaseMutex(idle_lock);
233 +                CloseHandle(idle_lock);
234 +        }
235 +        if (idle_sem) {
236 +                ReleaseSemaphore(idle_sem, 1, NULL);
237 +                CloseHandle(idle_sem);
238 +        }
239 + }
240 +
241 + void idle_wait(void)
242 + {
243 +        LOCK_IDLE;
244 +        if (idle_sem_ok > 0) {
245 +                idle_sem_ok++;
246 +                UNLOCK_IDLE;
247 +                WaitForSingleObject(idle_sem, INFINITE);
248 +                return;
249 +        }
250 +        UNLOCK_IDLE;
251 +
252 +        // Fallback: sleep 10 ms (this should not happen though)
253 +        Delay_usec(10000);
254 + }
255 +
256 +
257 + /*
258 + *  Resume execution of emulator thread, events just arrived
259 + */
260 +
261 + void idle_resume(void)
262 + {
263 +        LOCK_IDLE;
264 +        if (idle_sem_ok > 1) {
265 +                idle_sem_ok--;
266 +                UNLOCK_IDLE;
267 +                ReleaseSemaphore(idle_sem, 1, NULL);
268 +                return;
269 +        }
270 +        UNLOCK_IDLE;
271 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines