]> git.mxchange.org Git - flightgear.git/commitdiff
Prevent 100% CPU usage for FGCom standalone
authorTorsten Dreyer <torsten@t3r.de>
Thu, 6 Aug 2015 19:47:01 +0000 (21:47 +0200)
committerTorsten Dreyer <torsten@t3r.de>
Thu, 6 Aug 2015 19:47:01 +0000 (21:47 +0200)
Kévin Seroux:
As reported here (http://forum.flightgear.org/viewtopic.php?f=32&t=26629),
the FGCom standalone client use 100% of the CPU when it is in OBS mode. The fact to add the shortest sleep time
(1ms) has solved the problem. With this patch, I run FGCom with 1% of CPU usage instead of 100%.

utils/fgcom/fgcom.cxx

index d3cfa9c365c89b721c3527f79825b70f636ebb30..0a8f46d242402a2a1aa8446cc3ff142b7df6e17e 100644 (file)
@@ -147,8 +147,10 @@ int main(int argc, char** argv)
 
         while(_running) {
             int bytes = sgSocket.recv(currentPacket, sizeof(currentPacket)-1, 0);
-            if (bytes == -1)
+            if (bytes == -1) {
+                SGTimeStamp::sleepForMSec(1);  // Prevent full CPU usage (loop)
                 continue;
+            }
 
             currentPacket[bytes] = '\0';
             if( strcmp(currentPacket, previousPacket) != 0 ) {