From 2f42a8714c4fc8a03bebb0192ddad7ecc8376da9 Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 28 Oct 2013 14:51:36 +0000 Subject: [PATCH] Terrasync: don't busy wait when no requests are running. --- simgear/scene/tsync/terrasync.cxx | 6 ++++++ simgear/threads/SGQueue.hxx | 5 +++++ 2 files changed, 11 insertions(+) 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: /** -- 2.39.5