tweaks to _processLock to reduce time it's locked

This commit is contained in:
ZappoMan 2014-03-27 15:03:46 -07:00
parent 0fc83d81fd
commit c540427b9e

View file

@ -48,26 +48,28 @@ OctreeSendThread::~OctreeSendThread() {
}
void OctreeSendThread::setIsShuttingDown() {
QMutexLocker locker(&_processLock); // this will cause us to wait till the process loop is complete
_isShuttingDown = true;
OctreeServer::stopTrackingThread(this);
// this will cause us to wait till the process loop is complete, we do this after we change _isShuttingDown
QMutexLocker locker(&_processLock);
}
bool OctreeSendThread::process() {
if (_isShuttingDown) {
return false; // exit early if we're shutting down
}
OctreeServer::didProcess(this);
float lockWaitElapsedUsec = OctreeServer::SKIP_TIME;
quint64 lockWaitStart = usecTimestampNow();
QMutexLocker locker(&_processLock);
_processLock.lock();
quint64 lockWaitEnd = usecTimestampNow();
lockWaitElapsedUsec = (float)(lockWaitEnd - lockWaitStart);
OctreeServer::trackProcessWaitTime(lockWaitElapsedUsec);
if (_isShuttingDown) {
return false; // exit early if we're shutting down
}
quint64 start = usecTimestampNow();
// don't do any send processing until the initial load of the octree is complete...
@ -98,6 +100,12 @@ bool OctreeSendThread::process() {
}
}
_processLock.unlock();
if (_isShuttingDown) {
return false; // exit early if we're shutting down
}
// Only sleep if we're still running and we got the lock last time we tried, otherwise try to get the lock asap
if (isStillRunning()) {
// dynamically sleep until we need to fire off the next set of octree elements