fix new VoxelPersistThread behavior so it's actually only checking dirty bits every each persist cycle

This commit is contained in:
ZappoMan 2013-11-13 21:31:34 -08:00
parent 8805531b00
commit 1d272c333a
2 changed files with 4 additions and 6 deletions

View file

@ -60,7 +60,7 @@ bool VoxelPersistThread::process() {
VoxelNode::getSetChildAtIndexTime(), VoxelNode::getSetChildAtIndexCalls(), usecPerSet);
_initialLoadComplete = true;
_lastSave = usecTimestampNow(); // we just loaded, no need to save again
_lastCheck = usecTimestampNow(); // we just loaded, no need to save again
}
if (isStillRunning()) {
@ -68,15 +68,13 @@ bool VoxelPersistThread::process() {
uint64_t USECS_TO_SLEEP = 100 * MSECS_TO_USECS; // every 100ms
usleep(USECS_TO_SLEEP);
uint64_t now = usecTimestampNow();
uint64_t sinceLastSave = now - _lastSave;
uint64_t sinceLastSave = now - _lastCheck;
uint64_t intervalToCheck = _persistInterval * MSECS_TO_USECS;
if (sinceLastSave > intervalToCheck) {
qDebug("checking if voxels are dirty. sinceLastSave=%llu intervalToCheck=%llu\n", sinceLastSave, intervalToCheck);
// check the dirty bit and persist here...
_lastCheck = usecTimestampNow();
if (_tree->isDirty()) {
_lastSave = usecTimestampNow();
qDebug("saving voxels to file %s...\n",_filename);
_tree->writeToSVOFile(_filename);
_tree->clearDirtyBit(); // tree is clean after saving

View file

@ -38,7 +38,7 @@ private:
time_t _loadCompleted;
uint64_t _loadTimeUSecs;
uint64_t _lastSave;
uint64_t _lastCheck;
};
#endif // __voxel_server__VoxelPersistThread__