From: James Turner Date: Mon, 28 Oct 2013 14:51:36 +0000 (+0000) Subject: Terrasync: don't busy wait when no requests are running. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2f42a8714c4fc8a03bebb0192ddad7ecc8376da9;p=simgear.git Terrasync: don't busy wait when no requests are running. --- diff --git a/simgear/scene/tsync/terrasync.cxx b/simgear/scene/tsync/terrasync.cxx index afe89639..48c0c64f 100644 --- a/simgear/scene/tsync/terrasync.cxx +++ b/simgear/scene/tsync/terrasync.cxx @@ -643,6 +643,12 @@ void SGTerraSync::SvnThread::runInternal() } _busy = anySlotBusy; + if (!anySlotBusy) { + // wait on the blocking deque here, otherwise we spin + // the loop very fast, since _http::update with no connections + // active returns immediately. + waitingTiles.waitOnNotEmpty(); + } } // of thread running loop } diff --git a/simgear/threads/SGQueue.hxx b/simgear/threads/SGQueue.hxx index c4fab564..7f49b5d9 100644 --- a/simgear/threads/SGQueue.hxx +++ b/simgear/threads/SGQueue.hxx @@ -386,6 +386,11 @@ public: return this->queue.size(); } + void waitOnNotEmpty() { + SGGuard g(mutex); + while (this->queue.empty()) + not_empty.wait(mutex); + } private: /**