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

Comparing BasiliskII/src/Unix/timer_unix.cpp (file contents):
Revision 1.16 by gbeauche, 2005-02-21T22:57:03Z vs.
Revision 1.17 by gbeauche, 2005-06-30T10:20:18Z

# Line 297 | Line 297 | void Delay_usec(uint32 usec)
297   #endif
298          } while (was_error && (errno == EINTR));
299   }
300 +
301 +
302 + /*
303 + *  Suspend emulator thread, virtual CPU in idle mode
304 + */
305 +
306 + #ifdef HAVE_PTHREADS
307 + #if defined(HAVE_PTHREAD_COND_INIT)
308 + #define IDLE_USES_COND_WAIT 1
309 + static pthread_mutex_t idle_lock = PTHREAD_MUTEX_INITIALIZER;
310 + static pthread_cond_t idle_cond = PTHREAD_COND_INITIALIZER;
311 + #elif defined(HAVE_SEM_INIT)
312 + #define IDLE_USES_SEMAPHORE 1
313 + #include <semaphore.h>
314 + #ifdef HAVE_SPINLOCKS
315 + static spinlock_t idle_lock = SPIN_LOCK_UNLOCKED;
316 + #define LOCK_IDLE spin_lock(&idle_lock)
317 + #define UNLOCK_IDLE spin_unlock(&idle_lock)
318 + #else
319 + static pthread_mutex_t idle_lock = PTHREAD_MUTEX_INITIALIZER;
320 + #define LOCK_IDLE pthread_mutex_lock(&idle_lock)
321 + #define UNLOCK_IDLE pthread_mutex_unlock(&idle_lock)
322 + #endif
323 + static sem_t idle_sem;
324 + static int idle_sem_ok = -1;
325 + #endif
326 + #endif
327 +
328 + void idle_wait(void)
329 + {
330 + #ifdef IDLE_USES_COND_WAIT
331 +        pthread_cond_wait(&idle_cond, &idle_lock);
332 + #else
333 + #ifdef IDLE_USES_SEMAPHORE
334 +        if (idle_sem_ok < 0)
335 +                idle_sem_ok = (sem_init(&idle_sem, 0, 0) == 0);
336 +        if (idle_sem_ok > 0) {
337 +                LOCK_IDLE;
338 +                idle_sem_ok++;
339 +                UNLOCK_IDLE;
340 +                sem_wait(&idle_sem);
341 +                return;
342 +        }
343 + #endif
344 +        Delay_usec(10000);
345 + #endif
346 + }
347 +
348 +
349 + /*
350 + *  Resume execution of emulator thread, events just arrived
351 + */
352 +
353 + void idle_resume(void)
354 + {
355 + #ifdef IDLE_USES_COND_WAIT
356 +        pthread_cond_signal(&idle_cond);
357 + #else
358 + #ifdef IDLE_USES_SEMAPHORE
359 +        if (idle_sem_ok > 1) {
360 +                LOCK_IDLE;
361 +                idle_sem_ok--;
362 +                UNLOCK_IDLE;
363 +                sem_post(&idle_sem);
364 +                return;
365 +        }
366 + #endif
367 + #endif
368 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines