Merge pull request #7830 from ZappoMan/removeusleeps

switch OctreeSendThread and OctreePersistThread to use std::this_thread::sleep_for() instead of usleep()
This commit is contained in:
Brad Hefta-Gaub 2016-05-09 11:47:40 -07:00
commit ab0a77c82b
2 changed files with 15 additions and 6 deletions

View file

@ -9,6 +9,9 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <chrono>
#include <thread>
#include <NodeList.h>
#include <NumericalConstants.h>
#include <udt/PacketHeaders.h>
@ -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

View file

@ -9,6 +9,9 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <chrono>
#include <thread>
#include <cstdio>
#include <fstream>
#include <time.h>
@ -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();