From 99d35c37db29163013c93c058798703d80150a7f Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Fri, 6 May 2016 10:42:07 -0700 Subject: [PATCH 1/2] switch OctreeSendThread to use std::this_thread::sleep_for() instead of usleep() --- .../src/octree/OctreeSendThread.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/assignment-client/src/octree/OctreeSendThread.cpp b/assignment-client/src/octree/OctreeSendThread.cpp index ec812db8e8..94349bd3bc 100644 --- a/assignment-client/src/octree/OctreeSendThread.cpp +++ b/assignment-client/src/octree/OctreeSendThread.cpp @@ -9,6 +9,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include +#include + #include #include #include @@ -101,13 +104,16 @@ bool OctreeSendThread::process() { int elapsed = (usecTimestampNow() - start); int usecToSleep = OCTREE_SEND_INTERVAL_USECS - elapsed; - if (usecToSleep > 0) { - PerformanceWarning warn(false,"OctreeSendThread... usleep()",false,&_usleepTime,&_usleepCalls); - usleep(usecToSleep); - } else { + if (usecToSleep <= 0) { const int MIN_USEC_TO_SLEEP = 1; - usleep(MIN_USEC_TO_SLEEP); + usecToSleep = MIN_USEC_TO_SLEEP; } + + { + PerformanceWarning warn(false,"OctreeSendThread... usleep()",false,&_usleepTime,&_usleepCalls); + std::this_thread::sleep_for(std::chrono::microseconds(usecToSleep)); + } + } return isStillRunning(); // keep running till they terminate us From fe14bc8e52cc0823bb4e475467fbaedc67758251 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Fri, 6 May 2016 11:19:27 -0700 Subject: [PATCH 2/2] also switch OctreePersistThread to use std::this_thread::sleep_for() --- libraries/octree/src/OctreePersistThread.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/octree/src/OctreePersistThread.cpp b/libraries/octree/src/OctreePersistThread.cpp index 8169654b0c..d48c35d542 100644 --- a/libraries/octree/src/OctreePersistThread.cpp +++ b/libraries/octree/src/OctreePersistThread.cpp @@ -9,6 +9,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include +#include + #include #include #include @@ -201,7 +204,7 @@ bool OctreePersistThread::process() { if (isStillRunning()) { quint64 MSECS_TO_USECS = 1000; quint64 USECS_TO_SLEEP = 10 * MSECS_TO_USECS; // every 10ms - usleep(USECS_TO_SLEEP); + std::this_thread::sleep_for(std::chrono::microseconds(USECS_TO_SLEEP)); // do our updates then check to save... _tree->update();