2
2
* timer_unix.cpp - Time Manager emulation, Unix specific stuff
4
* Basilisk II (C) 1997-2002 Christian Bauer
4
* Basilisk II (C) 1997-2005 Christian Bauer
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
228
228
// Linux select() changes its timeout parameter upon return to contain
229
229
// the remaining time. Most other unixen leave it unchanged or undefined.
230
230
#define SELECT_SETS_REMAINING
231
#elif defined(__FreeBSD__) || defined(__sun__)
231
#elif defined(__FreeBSD__) || defined(__sun__) || (defined(__MACH__) && defined(__APPLE__))
232
232
#define USE_NANOSLEEP
233
233
#elif defined(HAVE_PTHREADS) && defined(sgi)
234
234
// SGI pthreads has a bug when using pthreads+signals+nanosleep,
298
298
} while (was_error && (errno == EINTR));
303
* Suspend emulator thread, virtual CPU in idle mode
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)
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)
323
static sem_t idle_sem;
324
static int idle_sem_ok = -1;
330
#ifdef IDLE_USES_COND_WAIT
331
pthread_mutex_lock(&idle_lock);
332
pthread_cond_wait(&idle_cond, &idle_lock);
333
pthread_mutex_unlock(&idle_lock);
335
#ifdef IDLE_USES_SEMAPHORE
337
idle_sem_ok = (sem_init(&idle_sem, 0, 0) == 0);
338
if (idle_sem_ok > 0) {
352
* Resume execution of emulator thread, events just arrived
355
void idle_resume(void)
357
#ifdef IDLE_USES_COND_WAIT
358
pthread_cond_signal(&idle_cond);
360
#ifdef IDLE_USES_SEMAPHORE
361
if (idle_sem_ok > 1) {