From: Toni Wilen Date: Sun, 7 Sep 2014 11:07:34 +0000 (+0300) Subject: Another spinlock implementation fix. Flush io pipe before switching to spinlock mode. X-Git-Tag: 3000~50 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=981b259780a0247186841dd37b99c5a3dfb560ff;p=francis%2Fwinuae.git Another spinlock implementation fix. Flush io pipe before switching to spinlock mode. --- diff --git a/events.cpp b/events.cpp index e12a97bb..aae737ef 100644 --- a/events.cpp +++ b/events.cpp @@ -74,7 +74,6 @@ void do_cycles_slow (unsigned long cycles_to_add) uae_ppc_execute_quick(0); } else { uae_ppc_execute_quick(1); - pissoff = pissoff_value; } } else { diff --git a/newcpu.cpp b/newcpu.cpp index a64044e2..513269f6 100644 --- a/newcpu.cpp +++ b/newcpu.cpp @@ -3165,9 +3165,9 @@ static bool haltloop(void) int lastintr = -1; // m68k stopped? Move PPC emulator to main thread. if (regs.halted < 0) { - uae_ppc_to_main_thread(); uae_ppc_spinlock_reset(); uae_ppc_spinlock_get(); + uae_ppc_to_main_thread(); write_log(_T("Entered m68k haltloop with PPC active\n")); } #endif diff --git a/ppc/ppc.cpp b/ppc/ppc.cpp index 165af886..6b6a6c4e 100644 --- a/ppc/ppc.cpp +++ b/ppc/ppc.cpp @@ -28,25 +28,37 @@ #define TRACE(format, ...) write_log(_T("PPC: ---------------- ") format, ## __VA_ARGS__) -volatile uae_u32 ppc_spinlock; +#ifdef _WIN32 +static volatile unsigned int ppc_spinlock, spinlock_cnt; +#endif void uae_ppc_spinlock_get(void) { #ifdef _WIN32 - int exchange = 1, compare = 0; while (true) { - if(InterlockedCompareExchange(&ppc_spinlock, exchange, compare) == 0) + if(InterlockedCompareExchange(&ppc_spinlock, 1, 0) == 0) { + if (spinlock_cnt) + write_log(_T("uae_ppc_spinlock_get %d!\n"), spinlock_cnt); + spinlock_cnt = 1; break; + } } +#else #endif } void uae_ppc_spinlock_release(void) { - ppc_spinlock = 0; +#ifdef _WIN32 + if (--spinlock_cnt) + write_log(_T("uae_ppc_spinlock_release %d!\n"), spinlock_cnt); + InterlockedExchange(&ppc_spinlock, 0); +#else +#endif } void uae_ppc_spinlock_reset(void) { + spinlock_cnt = 1; uae_ppc_spinlock_release(); } @@ -322,8 +334,17 @@ bool uae_ppc_to_main_thread(void) // QEMU: keep using thread if (ppc_implementation == PPC_IMPLEMENTATION_QEMU) { - ppc_io_pipe = false; + // already done? + if (ppc_io_pipe == false) + return true; + // make sure no new messages added to queue + ppc_cpu_lock_state = 1; ppc_use_spinlock = true; + // empty queue + while (comm_pipe_has_data(&ppcquery)) + uae_ppc_poll_queue(); + ppc_io_pipe = false; + ppc_cpu_lock_state = 0; return true; }