]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Another spinlock implementation fix. Flush io pipe before switching to spinlock mode.
authorToni Wilen <twilen@winuae.net>
Sun, 7 Sep 2014 11:07:34 +0000 (14:07 +0300)
committerToni Wilen <twilen@winuae.net>
Sun, 7 Sep 2014 11:07:34 +0000 (14:07 +0300)
events.cpp
newcpu.cpp
ppc/ppc.cpp

index e12a97bbe812dd585b6ad3a0256a34dc60d29c61..aae737efbb8c6838c0d3cf5e566fb660e0f65183 100644 (file)
@@ -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 {
index a64044e2f6a3ca66e9c52364c891b39acda955d4..513269f640c204e6d6bf635616512b1043c236fb 100644 (file)
@@ -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
index 165af8861e310b57a98d16079fd5f52840edee06..6b6a6c4e866ce0245e8df20034a6bd9a100ca350 100644 (file)
 #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;
        }