mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:35:08 +02:00
Fixed lack of resolution in usecTimestampNow()
This commit is contained in:
parent
ddf14b0842
commit
3eeb3a539d
5 changed files with 24 additions and 3 deletions
|
@ -17,6 +17,7 @@
|
|||
#include "AssignmentClientMonitor.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
initialiseUsecTimestampNow();
|
||||
|
||||
#ifndef WIN32
|
||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||
|
|
|
@ -18,10 +18,12 @@
|
|||
#include <QtCore/QCoreApplication>
|
||||
|
||||
#include <Logging.h>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "DomainServer.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
initialiseUsecTimestampNow();
|
||||
|
||||
#ifndef WIN32
|
||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <SharedUtil.h>
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
initialiseUsecTimestampNow();
|
||||
QElapsedTimer startupTime;
|
||||
startupTime.start();
|
||||
|
||||
|
|
|
@ -21,18 +21,34 @@
|
|||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QDateTime>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
#include "OctalCode.h"
|
||||
#include "SharedUtil.h"
|
||||
|
||||
int usecTimestampNowAdjust = 0;
|
||||
|
||||
static qint64 TIME_REFERENCE = 0; // in usec
|
||||
static QElapsedTimer timestampTimer;
|
||||
static int usecTimestampNowAdjust = 0; // in usec
|
||||
|
||||
void initialiseUsecTimestampNow() {
|
||||
static bool initialised = false;
|
||||
if (initialised) {
|
||||
qDebug() << "[WARNING] Double initialisation of usecTimestampNow().";
|
||||
return;
|
||||
}
|
||||
|
||||
TIME_REFERENCE = QDateTime::currentMSecsSinceEpoch() * 1000; // ms to usec
|
||||
initialised = true;
|
||||
}
|
||||
|
||||
void usecTimestampNowForceClockSkew(int clockSkew) {
|
||||
::usecTimestampNowAdjust = clockSkew;
|
||||
}
|
||||
|
||||
quint64 usecTimestampNow() {
|
||||
qint64 msecSinceEpoch = QDateTime::currentMSecsSinceEpoch();
|
||||
return msecSinceEpoch * 1000 + ::usecTimestampNowAdjust;
|
||||
// usec nsec to usec usec
|
||||
return TIME_REFERENCE + timestampTimer.nsecsElapsed() / 1000 + ::usecTimestampNowAdjust;
|
||||
}
|
||||
|
||||
float randFloat() {
|
||||
|
|
|
@ -60,6 +60,7 @@ static const quint64 USECS_PER_SECOND = USECS_PER_MSEC * MSECS_PER_SECOND;
|
|||
|
||||
const int BITS_IN_BYTE = 8;
|
||||
|
||||
void initialiseUsecTimestampNow();
|
||||
quint64 usecTimestampNow();
|
||||
void usecTimestampNowForceClockSkew(int clockSkew);
|
||||
|
||||
|
|
Loading…
Reference in a new issue