mirror of
https://github.com/kanjitalk755/macemu.git
synced 2024-07-27 00:31:28 +00:00
Add system-specific implementations of idle_{wait,resume} functions.
This commit is contained in:
parent
08c5f8b713
commit
e355c83f59
@ -130,3 +130,22 @@ void Delay_usec(uint32 usec)
|
|||||||
{
|
{
|
||||||
snooze(usec);
|
snooze(usec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Suspend emulator thread, virtual CPU in idle mode
|
||||||
|
*/
|
||||||
|
|
||||||
|
void idle_wait(void)
|
||||||
|
{
|
||||||
|
sleep(16667);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Resume execution of emulator thread, events just arrived
|
||||||
|
*/
|
||||||
|
|
||||||
|
void idle_resume(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
@ -202,6 +202,7 @@ AC_CHECK_LIB(pthread, pthread_create, , [
|
|||||||
if [[ "x$HAVE_PTHREADS" = "xyes" ]]; then
|
if [[ "x$HAVE_PTHREADS" = "xyes" ]]; then
|
||||||
AC_DEFINE(HAVE_PTHREADS, 1, [Define if pthreads are available.])
|
AC_DEFINE(HAVE_PTHREADS, 1, [Define if pthreads are available.])
|
||||||
fi
|
fi
|
||||||
|
AC_CHECK_FUNCS(pthread_cond_init)
|
||||||
AC_CHECK_FUNCS(pthread_cancel pthread_testcancel)
|
AC_CHECK_FUNCS(pthread_cancel pthread_testcancel)
|
||||||
AC_CHECK_FUNCS(pthread_mutexattr_setprotocol)
|
AC_CHECK_FUNCS(pthread_mutexattr_setprotocol)
|
||||||
AC_CHECK_FUNCS(pthread_mutexattr_settype)
|
AC_CHECK_FUNCS(pthread_mutexattr_settype)
|
||||||
|
@ -297,3 +297,72 @@ void Delay_usec(uint32 usec)
|
|||||||
#endif
|
#endif
|
||||||
} while (was_error && (errno == EINTR));
|
} while (was_error && (errno == EINTR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Suspend emulator thread, virtual CPU in idle mode
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_PTHREADS
|
||||||
|
#if defined(HAVE_PTHREAD_COND_INIT)
|
||||||
|
#define IDLE_USES_COND_WAIT 1
|
||||||
|
static pthread_mutex_t idle_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
static pthread_cond_t idle_cond = PTHREAD_COND_INITIALIZER;
|
||||||
|
#elif defined(HAVE_SEM_INIT)
|
||||||
|
#define IDLE_USES_SEMAPHORE 1
|
||||||
|
#include <semaphore.h>
|
||||||
|
#ifdef HAVE_SPINLOCKS
|
||||||
|
static spinlock_t idle_lock = SPIN_LOCK_UNLOCKED;
|
||||||
|
#define LOCK_IDLE spin_lock(&idle_lock)
|
||||||
|
#define UNLOCK_IDLE spin_unlock(&idle_lock)
|
||||||
|
#else
|
||||||
|
static pthread_mutex_t idle_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
#define LOCK_IDLE pthread_mutex_lock(&idle_lock)
|
||||||
|
#define UNLOCK_IDLE pthread_mutex_unlock(&idle_lock)
|
||||||
|
#endif
|
||||||
|
static sem_t idle_sem;
|
||||||
|
static int idle_sem_ok = -1;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void idle_wait(void)
|
||||||
|
{
|
||||||
|
#ifdef IDLE_USES_COND_WAIT
|
||||||
|
pthread_cond_wait(&idle_cond, &idle_lock);
|
||||||
|
#else
|
||||||
|
#ifdef IDLE_USES_SEMAPHORE
|
||||||
|
if (idle_sem_ok < 0)
|
||||||
|
idle_sem_ok = (sem_init(&idle_sem, 0, 0) == 0);
|
||||||
|
if (idle_sem_ok > 0) {
|
||||||
|
LOCK_IDLE;
|
||||||
|
idle_sem_ok++;
|
||||||
|
UNLOCK_IDLE;
|
||||||
|
sem_wait(&idle_sem);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
Delay_usec(10000);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Resume execution of emulator thread, events just arrived
|
||||||
|
*/
|
||||||
|
|
||||||
|
void idle_resume(void)
|
||||||
|
{
|
||||||
|
#ifdef IDLE_USES_COND_WAIT
|
||||||
|
pthread_cond_signal(&idle_cond);
|
||||||
|
#else
|
||||||
|
#ifdef IDLE_USES_SEMAPHORE
|
||||||
|
if (idle_sem_ok > 1) {
|
||||||
|
LOCK_IDLE;
|
||||||
|
idle_sem_ok--;
|
||||||
|
UNLOCK_IDLE;
|
||||||
|
sem_post(&idle_sem);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
@ -195,3 +195,22 @@ void Delay_usec(uint32 usec)
|
|||||||
// millisecond resolution anyway
|
// millisecond resolution anyway
|
||||||
Sleep(usec / 1000);
|
Sleep(usec / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Suspend emulator thread, virtual CPU in idle mode
|
||||||
|
*/
|
||||||
|
|
||||||
|
void idle_wait(void)
|
||||||
|
{
|
||||||
|
Delay_usec(10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Resume execution of emulator thread, events just arrived
|
||||||
|
*/
|
||||||
|
|
||||||
|
void idle_resume(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
@ -42,4 +42,8 @@ extern int timer_cmp_time(tm_time_t a, tm_time_t b);
|
|||||||
extern void timer_mac2host_time(tm_time_t &res, int32 mactime);
|
extern void timer_mac2host_time(tm_time_t &res, int32 mactime);
|
||||||
extern int32 timer_host2mac_time(tm_time_t hosttime);
|
extern int32 timer_host2mac_time(tm_time_t hosttime);
|
||||||
|
|
||||||
|
// Suspend execution of emulator thread and resume it on events
|
||||||
|
extern void idle_wait(void);
|
||||||
|
extern void idle_resume(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user