summaryrefslogtreecommitdiffstats
path: root/staging_vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-11-14 22:21:37 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2019-11-14 22:21:37 +0000
commit37754e26c8f04eb5a0d130f65e44946726fa5490 (patch)
treecc5cc48c3e7c26cd4881c93909fb14ef256b9b09 /staging_vespalib
parent52a5a424000cb4a1bcc61e601c6f4a183103e3d1 (diff)
Use steady clock to ensure monotonically increasing clock.
Diffstat (limited to 'staging_vespalib')
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/clock.cpp7
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/clock.h10
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/doom.h2
3 files changed, 10 insertions, 9 deletions
diff --git a/staging_vespalib/src/vespa/vespalib/util/clock.cpp b/staging_vespalib/src/vespa/vespalib/util/clock.cpp
index c9768417914..10d075a21bd 100644
--- a/staging_vespalib/src/vespa/vespalib/util/clock.cpp
+++ b/staging_vespalib/src/vespa/vespalib/util/clock.cpp
@@ -5,6 +5,7 @@
#include <chrono>
using namespace fastos;
+using namespace std::chrono;
namespace vespalib {
@@ -27,7 +28,7 @@ Clock::~Clock()
void Clock::setTime() const
{
- _timeNS = ClockSystem::adjustTick2Sec(ClockSystem::now());
+ _timeNS = duration_cast<nanoseconds>(steady_clock::now().time_since_epoch()).count();
}
void Clock::Run(FastOS_ThreadInterface *thread, void *arguments)
@@ -37,13 +38,13 @@ void Clock::Run(FastOS_ThreadInterface *thread, void *arguments)
std::unique_lock<std::mutex> guard(_lock);
while ( ! thread->GetBreakFlag() && !_stop) {
setTime();
- _cond.wait_for(guard, std::chrono::milliseconds(_timePeriodMS));
+ _cond.wait_for(guard, milliseconds(_timePeriodMS));
}
_running = false;
}
void
-Clock::stop(void)
+Clock::stop()
{
std::lock_guard<std::mutex> guard(_lock);
_stop = true;
diff --git a/staging_vespalib/src/vespa/vespalib/util/clock.h b/staging_vespalib/src/vespa/vespalib/util/clock.h
index 75f407ec95d..b44b1454cd4 100644
--- a/staging_vespalib/src/vespa/vespalib/util/clock.h
+++ b/staging_vespalib/src/vespa/vespalib/util/clock.h
@@ -21,11 +21,11 @@ private:
Clock & operator = (const Clock &);
mutable fastos::TimeStamp _timeNS;
- int _timePeriodMS;
- std::mutex _lock;
- std::condition_variable _cond;
- bool _stop;
- bool _running;
+ int _timePeriodMS;
+ std::mutex _lock;
+ std::condition_variable _cond;
+ bool _stop;
+ bool _running;
void setTime() const;
diff --git a/staging_vespalib/src/vespa/vespalib/util/doom.h b/staging_vespalib/src/vespa/vespalib/util/doom.h
index 3b7259f891d..623cc23fcc8 100644
--- a/staging_vespalib/src/vespa/vespalib/util/doom.h
+++ b/staging_vespalib/src/vespa/vespalib/util/doom.h
@@ -2,7 +2,7 @@
#pragma once
-#include <vespa/vespalib/util/clock.h>
+#include "clock.h"
namespace vespalib {