From c540427b9e25a6aac8185455550daab7052a08f3 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 27 Mar 2014 15:03:46 -0700 Subject: [PATCH] tweaks to _processLock to reduce time it's locked --- .../src/octree/OctreeSendThread.cpp | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/assignment-client/src/octree/OctreeSendThread.cpp b/assignment-client/src/octree/OctreeSendThread.cpp index 023f3f3d2c..4105b21eb8 100644 --- a/assignment-client/src/octree/OctreeSendThread.cpp +++ b/assignment-client/src/octree/OctreeSendThread.cpp @@ -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