diff --git a/SheepShaver/src/Unix/main_unix.cpp b/SheepShaver/src/Unix/main_unix.cpp index 3cc63481..890c3df2 100644 --- a/SheepShaver/src/Unix/main_unix.cpp +++ b/SheepShaver/src/Unix/main_unix.cpp @@ -232,11 +232,7 @@ static void sigill_handler(int sig, sigcontext_struct *sc); // From asm_linux.S -#if EMULATED_PPC -extern int atomic_add(int *var, int v); -extern int atomic_and(int *var, int v); -extern int atomic_or(int *var, int v); -#else +#if !EMULATED_PPC extern "C" void *get_toc(void); extern "C" void *get_sp(void); extern "C" void flush_icache_range(void *start, void *end); @@ -251,6 +247,47 @@ extern void paranoia_check(void); #endif +#if EMULATED_PPC +/* + * Atomic operations + */ + +#if HAVE_SPINLOCKS +static spinlock_t atomic_ops_lock = SPIN_LOCK_UNLOCKED; +#else +#define spin_lock(LOCK) +#define spin_unlock(LOCK) +#endif + +int atomic_add(int *var, int v) +{ + spin_lock(&atomic_ops_lock); + int ret = *var; + *var += v; + spin_unlock(&atomic_ops_lock); + return ret; +} + +int atomic_and(int *var, int v) +{ + spin_lock(&atomic_ops_lock); + int ret = *var; + *var &= v; + spin_unlock(&atomic_ops_lock); + return ret; +} + +int atomic_or(int *var, int v) +{ + spin_lock(&atomic_ops_lock); + int ret = *var; + *var |= v; + spin_unlock(&atomic_ops_lock); + return ret; +} +#endif + + /* * Main program */ diff --git a/SheepShaver/src/kpx_cpu/sheepshaver_glue.cpp b/SheepShaver/src/kpx_cpu/sheepshaver_glue.cpp index 9430ee2b..61c0057d 100644 --- a/SheepShaver/src/kpx_cpu/sheepshaver_glue.cpp +++ b/SheepShaver/src/kpx_cpu/sheepshaver_glue.cpp @@ -57,7 +57,7 @@ static void enter_mon(void) } // Enable multicore (main/interrupts) cpu emulation? -#define MULTICORE_CPU 0 +#define MULTICORE_CPU (ASYNC_IRQ ? 1 : 0) // Enable Execute68k() safety checks? #define SAFE_EXEC_68K 1 @@ -604,11 +604,6 @@ void emul_ppc(uint32 entry) * Handle PowerPC interrupt */ -// Atomic operations -extern int atomic_add(int *var, int v); -extern int atomic_and(int *var, int v); -extern int atomic_or(int *var, int v); - #if !ASYNC_IRQ void TriggerInterrupt(void) { @@ -901,31 +896,6 @@ uint32 call_macos7(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 a return current_cpu->execute_macos_code(tvect, sizeof(args)/sizeof(args[0]), args); } -/* - * Atomic operations - */ - -int atomic_add(int *var, int v) -{ - int ret = *var; - *var += v; - return ret; -} - -int atomic_and(int *var, int v) -{ - int ret = *var; - *var &= v; - return ret; -} - -int atomic_or(int *var, int v) -{ - int ret = *var; - *var |= v; - return ret; -} - /* * Resource Manager thunks */