]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
sys: [Windows] fix spinning instead of sleeping
authorbones_was_here <bones_was_here@xonotic.au>
Mon, 8 Apr 2024 00:41:52 +0000 (10:41 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Thu, 11 Apr 2024 12:10:45 +0000 (22:10 +1000)
For 231beb2c234914f942166eb152c44e55b5b01f86 I tested incorrectly, using
Task Manager inside the VM which reports low CPU load even when spinning.
DP's `status` command showed the correct result.

Changes the default path from select() to: usleep() on POSIX, Sleep() on
Windows.

Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
sys_shared.c

index 745a839eb6ae0f1bfe9594a6f4695e5e9354d308..d06c88499b1cc5db5a05f5c8d6026a5afc4d8777 100644 (file)
@@ -508,7 +508,7 @@ double Sys_Sleep(double time)
        else if(sys_supportsdlgetticks && sys_usesdldelay.integer)
                Sys_SDL_Delay(microseconds / 1000);
 #if HAVE_SELECT
-       else
+       else if (cls.state == ca_dedicated && sv_checkforpacketsduringsleep.integer)
        {
                struct timeval tv;
                lhnetsocket_t *s;
@@ -516,30 +516,27 @@ double Sys_Sleep(double time)
                int lastfd = -1;
 
                FD_ZERO(&fdreadset);
-               if (cls.state == ca_dedicated && sv_checkforpacketsduringsleep.integer)
+               List_For_Each_Entry(s, &lhnet_socketlist.list, lhnetsocket_t, list)
                {
-                       List_For_Each_Entry(s, &lhnet_socketlist.list, lhnetsocket_t, list)
+                       if (s->address.addresstype == LHNETADDRESSTYPE_INET4 || s->address.addresstype == LHNETADDRESSTYPE_INET6)
                        {
-                               if (s->address.addresstype == LHNETADDRESSTYPE_INET4 || s->address.addresstype == LHNETADDRESSTYPE_INET6)
-                               {
-                                       if (lastfd < s->inetsocket)
-                                               lastfd = s->inetsocket;
+                               if (lastfd < s->inetsocket)
+                                       lastfd = s->inetsocket;
        #if defined(WIN32) && !defined(_MSC_VER)
-                                       FD_SET((int)s->inetsocket, &fdreadset);
+                               FD_SET((int)s->inetsocket, &fdreadset);
        #else
-                                       FD_SET((unsigned int)s->inetsocket, &fdreadset);
+                               FD_SET((unsigned int)s->inetsocket, &fdreadset);
        #endif
-                               }
                        }
                }
                tv.tv_sec = microseconds / 1000000;
                tv.tv_usec = microseconds % 1000000;
                // on Win32, select() cannot be used with all three FD list args being NULL according to MSDN
-               // (so much for POSIX...)
-               // bones_was_here: but a zeroed fd_set seems to be tolerated (tested on Win 7)
+               // (so much for POSIX...), not with an empty fd_set either.
                select(lastfd + 1, &fdreadset, NULL, NULL, &tv);
        }
-#elif HAVE_USLEEP
+#endif
+#if HAVE_USLEEP
        else
                usleep(microseconds);
 #elif HAVE_Sleep