Update persistInterval to use std::chrono in OctreePersistThread

This commit is contained in:
Ryan Huffman 2018-05-10 15:51:55 -07:00
parent 8f4f3db9ce
commit d0af06939f
4 changed files with 17 additions and 12 deletions

View file

@ -1050,8 +1050,13 @@ void OctreeServer::readConfiguration() {
_persistAsFileType = "json.gz";
_persistInterval = OctreePersistThread::DEFAULT_PERSIST_INTERVAL;
readOptionInt(QString("persistInterval"), settingsSectionObject, _persistInterval);
qDebug() << "persistInterval=" << _persistInterval;
int result { -1 };
readOptionInt(QString("persistInterval"), settingsSectionObject, result);
if (result != -1) {
_persistInterval = std::chrono::seconds(result);
}
qDebug() << "persistInterval=" << _persistInterval.count();
readOptionBool(QString("persistFileDownload"), settingsSectionObject, _persistFileDownload);
qDebug() << "persistFileDownload=" << _persistFileDownload;

View file

@ -193,7 +193,7 @@ protected:
OctreePersistThread* _persistManager;
QThread _persistThread;
int _persistInterval;
std::chrono::milliseconds _persistInterval;
bool _persistFileDownload;
int _maxBackupVersions;

View file

@ -36,13 +36,12 @@
#include "OctreeUtils.h"
#include "OctreeDataUtils.h"
const int OctreePersistThread::DEFAULT_PERSIST_INTERVAL { 1000 * 30 }; // every 30 seconds
const std::chrono::seconds OctreePersistThread::DEFAULT_PERSIST_INTERVAL { 30 };
constexpr int MAX_OCTREE_REPLACEMENT_BACKUP_FILES_COUNT { 20 };
//constexpr int MAX_OCTREE_REPLACEMENT_BACKUP_FILES_SIZE_BYTES { 50 * 1000 * 1000 };
constexpr size_t MAX_OCTREE_REPLACEMENT_BACKUP_FILES_SIZE_BYTES { 70000 };
constexpr size_t MAX_OCTREE_REPLACEMENT_BACKUP_FILES_SIZE_BYTES { 50 * 1000 * 1000 };
OctreePersistThread::OctreePersistThread(OctreePointer tree, const QString& filename, int persistInterval,
OctreePersistThread::OctreePersistThread(OctreePointer tree, const QString& filename, std::chrono::milliseconds persistInterval,
bool debugTimestampNow, QString persistAsFileType) :
_tree(tree),
_filename(filename),
@ -187,7 +186,8 @@ void OctreePersistThread::handleOctreeDataFileReply(QSharedPointer<ReceivedMessa
}
qDebug() << "Starting timer";
QTimer::singleShot(_persistInterval, this, &OctreePersistThread::process);
QTimer::singleShot(std::chrono::milliseconds(_persistInterval).count(), this, &OctreePersistThread::process);
QTimer::singleShot(std::chrono::milliseconds(1000).count(), this, &OctreePersistThread::process);
emit loadCompleted();
}
@ -246,7 +246,7 @@ bool OctreePersistThread::process() {
quint64 now = usecTimestampNow();
quint64 sinceLastSave = now - _lastCheck;
quint64 intervalToCheck = _persistInterval * MSECS_TO_USECS;
quint64 intervalToCheck = std::chrono::microseconds(_persistInterval).count();
if (sinceLastSave > intervalToCheck) {
_lastCheck = now;

View file

@ -30,11 +30,11 @@ public:
quint64 lastBackup;
};
static const int DEFAULT_PERSIST_INTERVAL;
static const std::chrono::seconds DEFAULT_PERSIST_INTERVAL;
OctreePersistThread(OctreePointer tree,
const QString& filename,
int persistInterval = DEFAULT_PERSIST_INTERVAL,
std::chrono::milliseconds persistInterval = DEFAULT_PERSIST_INTERVAL,
bool debugTimestampNow = false,
QString persistAsFileType = "json.gz");
@ -70,7 +70,7 @@ protected:
private:
OctreePointer _tree;
QString _filename;
int _persistInterval;
std::chrono::milliseconds _persistInterval;
bool _initialLoadComplete;
quint64 _loadTimeUSecs;