From 7294999f351c3c178685e9768a8110da24de23ca Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Thu, 6 Aug 2015 21:47:01 +0200 Subject: [PATCH] Prevent 100% CPU usage for FGCom standalone MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/fgcom/fgcom.cxx b/utils/fgcom/fgcom.cxx index d3cfa9c36..0a8f46d24 100644 --- a/utils/fgcom/fgcom.cxx +++ b/utils/fgcom/fgcom.cxx @@ -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 ) { -- 2.39.5