]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
slirp: avoid Unix thread sentinel in shared code
authorStefan Reinauer <stefan.reinauer@coreboot.org>
Thu, 28 May 2026 15:08:36 +0000 (08:08 -0700)
committerStefan Reinauer <stefan.reinauer@coreboot.org>
Tue, 2 Jun 2026 22:33:30 +0000 (15:33 -0700)
Track whether the builtin slirp helper thread was started. Do not
write BAD_THREAD into uae_thread_id from common code because Windows
uses HANDLE thread IDs and does not define that Unix sentinel.

slirp_uae.cpp

index af022bbfe3a93c73b21089a6c489c6346d054820..8758532e6b8d319ed50295cbce386514e39e8df2 100644 (file)
@@ -135,6 +135,7 @@ int uae_slirp_redir(int is_udp, int host_port, struct in_addr guest_addr,
 
 static volatile int slirp_thread_active;
 static uae_thread_id slirp_tid;
+static bool slirp_thread_started;
 extern uae_sem_t slirp_sem2;
 
 static void slirp_receive_func(void *arg)
@@ -203,8 +204,14 @@ bool uae_slirp_start (void)
 #ifdef WITH_BUILTIN_SLIRP
        if (impl == BUILTIN_IMPLEMENTATION) {
                uae_slirp_end ();
-               uae_start_thread(_T("slirp-receive"), slirp_receive_func, NULL,
-                                                &slirp_tid);
+               slirp_thread_active = 1;
+               if (!uae_start_thread(_T("slirp-receive"), slirp_receive_func, NULL,
+                                                &slirp_tid)) {
+                       slirp_thread_active = 0;
+                       slirp_thread_started = false;
+                       return false;
+               }
+               slirp_thread_started = true;
                return true;
        }
 #endif
@@ -221,20 +228,10 @@ void uae_slirp_end(void)
 #endif
 #ifdef WITH_BUILTIN_SLIRP
        if (impl == BUILTIN_IMPLEMENTATION) {
-               if (slirp_thread_active > 0) {
+               if (slirp_thread_started) {
                        slirp_thread_active = 0;
-                       // Use a proper timeout instead of infinite waiting
-                       int wait_count = 0;
-                       while (slirp_thread_active == 0 && wait_count < 100) {
-                               sleep_millis(10);
-                               wait_count++;
-                       }
-
-                       // Force thread termination if it didn't exit cleanly
-                       if (slirp_thread_active == 0) {
-                               write_log(_T("SLIRP thread did not terminate properly, forcing exit\n"));
-                       }
-                       uae_end_thread(&slirp_tid);
+                       uae_wait_thread(slirp_tid);
+                       slirp_thread_started = false;
                }
                slirp_thread_active = 0;
                return;