aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-12-15 15:44:55 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-12-15 15:49:37 +0000
commit3a1502c2e21eec47d34d73bb5ba641dfec51a5c2 (patch)
tree10ad6d5d3d4d49b89f32f2ef974e1aad2e64a5e6 /vespalib
parent28f8cf3e298d51ca703ceee36a992297d38637cc (diff)
Remove most of the now void clock indirection.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/util/clock.h1
-rw-r--r--vespalib/src/vespa/vespalib/util/doom.cpp4
-rw-r--r--vespalib/src/vespa/vespalib/util/doom.h22
-rw-r--r--vespalib/src/vespa/vespalib/util/fake_doom.cpp3
-rw-r--r--vespalib/src/vespa/vespalib/util/fake_doom.h1
-rw-r--r--vespalib/src/vespa/vespalib/util/testclock.cpp8
-rw-r--r--vespalib/src/vespa/vespalib/util/testclock.h6
7 files changed, 26 insertions, 19 deletions
diff --git a/vespalib/src/vespa/vespalib/util/clock.h b/vespalib/src/vespa/vespalib/util/clock.h
index 1e37e3fff8d..ab4671f7bfb 100644
--- a/vespalib/src/vespa/vespalib/util/clock.h
+++ b/vespalib/src/vespa/vespalib/util/clock.h
@@ -28,6 +28,7 @@ public:
vespalib::steady_time getTimeNS() const noexcept {
return vespalib::steady_time(_timeNS.load(std::memory_order_relaxed));
}
+ const std::atomic<steady_time> & nowRef() const { return _timeNS; }
};
}
diff --git a/vespalib/src/vespa/vespalib/util/doom.cpp b/vespalib/src/vespa/vespalib/util/doom.cpp
index 8fc82031e79..66df17e8897 100644
--- a/vespalib/src/vespa/vespalib/util/doom.cpp
+++ b/vespalib/src/vespa/vespalib/util/doom.cpp
@@ -5,9 +5,9 @@
namespace vespalib {
-Doom::Doom(const Clock &clock, steady_time softDoom,
+Doom::Doom(const std::atomic<steady_time> & now_ref, steady_time softDoom,
steady_time hardDoom, bool explicitSoftDoom) noexcept
- : _clock(clock),
+ : _now(now_ref),
_softDoom(softDoom),
_hardDoom(hardDoom),
_isExplicitSoftDoom(explicitSoftDoom)
diff --git a/vespalib/src/vespa/vespalib/util/doom.h b/vespalib/src/vespa/vespalib/util/doom.h
index 1d7070cedd0..c9b66725b0f 100644
--- a/vespalib/src/vespa/vespalib/util/doom.h
+++ b/vespalib/src/vespa/vespalib/util/doom.h
@@ -2,26 +2,30 @@
#pragma once
-#include "clock.h"
+#include "time.h"
+#include <atomic>
namespace vespalib {
class Doom {
public:
- Doom(const Clock &clock, steady_time doom) noexcept
- : Doom(clock, doom, doom, false)
+ Doom(const std::atomic<steady_time> & now_ref, steady_time doom) noexcept
+ : Doom(now_ref, doom, doom, false)
{}
- Doom(const Clock &clock, steady_time softDoom,
+ Doom(const std::atomic<steady_time> & now_ref, steady_time softDoom,
steady_time hardDoom, bool explicitSoftDoom) noexcept;
- bool soft_doom() const noexcept { return (_clock.getTimeNS() > _softDoom); }
- bool hard_doom() const noexcept { return (_clock.getTimeNS() > _hardDoom); }
- duration soft_left() const noexcept { return _softDoom - _clock.getTimeNS(); }
- duration hard_left() const noexcept { return _hardDoom - _clock.getTimeNS(); }
+ bool soft_doom() const noexcept { return (getTimeNS() > _softDoom); }
+ bool hard_doom() const noexcept { return (getTimeNS() > _hardDoom); }
+ duration soft_left() const noexcept { return _softDoom - getTimeNS(); }
+ duration hard_left() const noexcept { return _hardDoom - getTimeNS(); }
bool isExplicitSoftDoom() const noexcept { return _isExplicitSoftDoom; }
static const Doom & never() noexcept;
private:
- const Clock &_clock;
+ vespalib::steady_time getTimeNS() const noexcept {
+ return vespalib::steady_time(_now.load(std::memory_order_relaxed));
+ }
+ const std::atomic<steady_time> & _now;
steady_time _softDoom;
steady_time _hardDoom;
bool _isExplicitSoftDoom;
diff --git a/vespalib/src/vespa/vespalib/util/fake_doom.cpp b/vespalib/src/vespa/vespalib/util/fake_doom.cpp
index d9cbce0b152..eeedc555d21 100644
--- a/vespalib/src/vespa/vespalib/util/fake_doom.cpp
+++ b/vespalib/src/vespa/vespalib/util/fake_doom.cpp
@@ -6,8 +6,7 @@ namespace vespalib {
FakeDoom::FakeDoom(steady_time::duration time_to_doom) noexcept
: _time(steady_clock::now()),
- _clock(_time),
- _doom(_clock, _clock.getTimeNS() + time_to_doom)
+ _doom(_time, _time.load(std::memory_order_relaxed) + time_to_doom)
{
}
diff --git a/vespalib/src/vespa/vespalib/util/fake_doom.h b/vespalib/src/vespa/vespalib/util/fake_doom.h
index 1e6cfcb0c4d..a5c25ac4d9d 100644
--- a/vespalib/src/vespa/vespalib/util/fake_doom.h
+++ b/vespalib/src/vespa/vespalib/util/fake_doom.h
@@ -12,7 +12,6 @@ namespace vespalib {
*/
class FakeDoom {
std::atomic<steady_time> _time;
- Clock _clock;
Doom _doom;
public:
FakeDoom() noexcept : FakeDoom(1s) { }
diff --git a/vespalib/src/vespa/vespalib/util/testclock.cpp b/vespalib/src/vespa/vespalib/util/testclock.cpp
index 9f63ce6c217..fe2da504150 100644
--- a/vespalib/src/vespa/vespalib/util/testclock.cpp
+++ b/vespalib/src/vespa/vespalib/util/testclock.cpp
@@ -6,11 +6,15 @@
namespace vespalib {
TestClock::TestClock()
- : _ticker(std::make_unique<InvokeServiceImpl>(10ms)),
- _clock(_ticker->nowRef())
+ : _ticker(std::make_unique<InvokeServiceImpl>(10ms))
{
}
TestClock::~TestClock() = default;
+const std::atomic<steady_time> &
+TestClock::nowRef() const {
+ return _ticker->nowRef();
+}
+
}
diff --git a/vespalib/src/vespa/vespalib/util/testclock.h b/vespalib/src/vespa/vespalib/util/testclock.h
index 748c239b309..117e19bedb8 100644
--- a/vespalib/src/vespa/vespalib/util/testclock.h
+++ b/vespalib/src/vespa/vespalib/util/testclock.h
@@ -1,7 +1,8 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
-#include "clock.h"
+#include "time.h"
+#include <atomic>
namespace vespalib {
@@ -15,7 +16,6 @@ class TestClock
{
private:
std::unique_ptr<InvokeServiceImpl> _ticker;
- Clock _clock;
public:
TestClock();
TestClock(const TestClock &) = delete;
@@ -23,7 +23,7 @@ public:
TestClock(TestClock &&) = delete;
TestClock & operator =(TestClock &&) = delete;
~TestClock();
- const Clock & clock() { return _clock; }
+ const std::atomic<steady_time> & nowRef() const;
};
}