Merge pull request #1255 from ZappoMan/bugfixes

use node->trylock() in VoxelSendThread() to handle shutdown race condition
This commit is contained in:
Stephen Birarda 2013-11-13 15:18:24 -08:00
commit 9db961b612
2 changed files with 32 additions and 21 deletions

View file

@ -71,6 +71,9 @@ public:
void setPingMs(int pingMs) { _pingMs = pingMs; }
void lock() { pthread_mutex_lock(&_mutex); }
/// returns false if lock failed, true if you got the lock
bool trylock() { return (pthread_mutex_trylock(&_mutex) == 0); }
void unlock() { pthread_mutex_unlock(&_mutex); }
static void printLog(Node const&);

View file

@ -31,7 +31,8 @@ bool VoxelSendThread::process() {
Node* node = NodeList::getInstance()->nodeWithUUID(_nodeUUID);
if (node) {
node->lock(); // make sure the node list doesn't kill our node while we're using it
// make sure the node list doesn't kill our node while we're using it
if (node->trylock()) {
VoxelNodeData* nodeData = NULL;
nodeData = (VoxelNodeData*) node->getLinkedData();
@ -48,6 +49,10 @@ bool VoxelSendThread::process() {
}
node->unlock(); // we're done with this node for now.
} else {
qDebug("VoxelSendThread::process() failed to lock node...isStillRunning()=%s\n",
debug::valueOf(isStillRunning()));
}
}
} else {
if (_myServer->wantsDebugVoxelSending()) {
@ -55,6 +60,8 @@ bool VoxelSendThread::process() {
}
}
// Only sleep if we're still running...
if (isStillRunning()) {
// dynamically sleep until we need to fire off the next set of voxels
int elapsed = (usecTimestampNow() - start);
int usecToSleep = VOXEL_SEND_INTERVAL_USECS - elapsed;
@ -66,6 +73,7 @@ bool VoxelSendThread::process() {
std::cout << "Last send took too much time, not sleeping!\n";
}
}
}
return isStillRunning(); // keep running till they terminate us
}