lock our node while using it to prevent crash on domain shutdown

This commit is contained in:
ZappoMan 2013-11-06 13:52:31 -08:00
parent 5cd0ecde18
commit c3914e648f

View file

@ -27,11 +27,12 @@ bool VoxelSendThread::process() {
uint64_t start = usecTimestampNow(); uint64_t start = usecTimestampNow();
Node* node = NodeList::getInstance()->nodeWithUUID(_nodeUUID); Node* node = NodeList::getInstance()->nodeWithUUID(_nodeUUID);
VoxelNodeData* nodeData = NULL;
if (node) { if (node) {
node->lock(); // make sure the node list doesn't kill our node while we're using it
VoxelNodeData* nodeData = NULL;
nodeData = (VoxelNodeData*) node->getLinkedData(); nodeData = (VoxelNodeData*) node->getLinkedData();
}
int packetsSent = 0; int packetsSent = 0;
@ -44,6 +45,9 @@ bool VoxelSendThread::process() {
packetsSent = deepestLevelVoxelDistributor(node, nodeData, viewFrustumChanged); packetsSent = deepestLevelVoxelDistributor(node, nodeData, viewFrustumChanged);
} }
node->unlock(); // we're done with this node for now.
}
// dynamically sleep until we need to fire off the next set of voxels // dynamically sleep until we need to fire off the next set of voxels
int elapsed = (usecTimestampNow() - start); int elapsed = (usecTimestampNow() - start);
int usecToSleep = VOXEL_SEND_INTERVAL_USECS - elapsed; int usecToSleep = VOXEL_SEND_INTERVAL_USECS - elapsed;
@ -55,6 +59,7 @@ bool VoxelSendThread::process() {
std::cout << "Last send took too much time, not sleeping!\n"; std::cout << "Last send took too much time, not sleeping!\n";
} }
} }
return isStillRunning(); // keep running till they terminate us return isStillRunning(); // keep running till they terminate us
} }