From 11058355a01e98c3ac0e26c917224f4b7ae164bb Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 14 Nov 2014 09:55:32 -0800 Subject: [PATCH] implement aboutToFinish for persist thread to allow final save before shutdown --- assignment-client/src/octree/OctreeServer.cpp | 3 ++ libraries/entities/src/EntityTree.cpp | 2 - libraries/octree/src/OctreePersistThread.cpp | 38 +++++++++++++------ libraries/octree/src/OctreePersistThread.h | 4 ++ 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/assignment-client/src/octree/OctreeServer.cpp b/assignment-client/src/octree/OctreeServer.cpp index 26cf94269b..34378effd3 100644 --- a/assignment-client/src/octree/OctreeServer.cpp +++ b/assignment-client/src/octree/OctreeServer.cpp @@ -1197,6 +1197,9 @@ void OctreeServer::aboutToFinish() { qDebug() << qPrintable(_safeServerName) << "server about to finish while node still connected node:" << *node; forceNodeShutdown(node); } + if (_persistThread) { + _persistThread->aboutToFinish(); + } qDebug() << qPrintable(_safeServerName) << "server ENDING about to finish..."; } diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index bc2823e15c..73957ad077 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -1089,7 +1089,6 @@ bool DebugOperator::preRecursion(OctreeElement* element) { } void EntityTree::dumpTree() { - // First, look for the existing entity in the tree.. DebugOperator theOperator; recurseTreeWithOperator(&theOperator); } @@ -1107,7 +1106,6 @@ bool PruneOperator::postRecursion(OctreeElement* element) { } void EntityTree::pruneTree() { - // First, look for the existing entity in the tree.. PruneOperator theOperator; recurseTreeWithOperator(&theOperator); } diff --git a/libraries/octree/src/OctreePersistThread.cpp b/libraries/octree/src/OctreePersistThread.cpp index 406681c2c5..dd81b3ff4d 100644 --- a/libraries/octree/src/OctreePersistThread.cpp +++ b/libraries/octree/src/OctreePersistThread.cpp @@ -78,19 +78,33 @@ bool OctreePersistThread::process() { quint64 intervalToCheck = _persistInterval * MSECS_TO_USECS; if (sinceLastSave > intervalToCheck) { - // check the dirty bit and persist here... - _lastCheck = usecTimestampNow(); - if (_tree->isDirty()) { - qDebug() << "pruning Octree before saving..."; - _tree->pruneTree(); - qDebug() << "DONE pruning Octree before saving..."; - - qDebug() << "saving Octree to file " << _filename << "..."; - _tree->writeToSVOFile(_filename.toLocal8Bit().constData()); - _tree->clearDirtyBit(); // tree is clean after saving - qDebug("DONE saving Octree to file..."); - } + _lastCheck = now; + persistOperation(); } } return isStillRunning(); // keep running till they terminate us } + + +void OctreePersistThread::aboutToFinish() { + qDebug() << "Persist thread about to finish..."; + persistOperation(); + qDebug() << "Persist thread done with about to finish..."; +} + +void OctreePersistThread::persistOperation() { + if (_tree->isDirty()) { + _tree->lockForWrite(); + { + qDebug() << "pruning Octree before saving..."; + _tree->pruneTree(); + qDebug() << "DONE pruning Octree before saving..."; + } + _tree->unlock(); + + qDebug() << "saving Octree to file " << _filename << "..."; + _tree->writeToSVOFile(_filename.toLocal8Bit().constData()); + _tree->clearDirtyBit(); // tree is clean after saving + qDebug("DONE saving Octree to file..."); + } +} diff --git a/libraries/octree/src/OctreePersistThread.h b/libraries/octree/src/OctreePersistThread.h index 2f86320b2e..c4bccd55b9 100644 --- a/libraries/octree/src/OctreePersistThread.h +++ b/libraries/octree/src/OctreePersistThread.h @@ -29,12 +29,16 @@ public: bool isInitialLoadComplete() const { return _initialLoadComplete; } quint64 getLoadElapsedTime() const { return _loadTimeUSecs; } + void aboutToFinish(); /// call this to inform the persist thread that the owner is about to finish to support final persist + signals: void loadCompleted(); protected: /// Implements generic processing behavior for this thread. virtual bool process(); + + void persistOperation(); private: Octree* _tree; QString _filename;