summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/util/clock.h2
-rw-r--r--vespalib/src/vespa/vespalib/util/doom.cpp7
-rw-r--r--vespalib/src/vespa/vespalib/util/doom.h1
-rw-r--r--vespalib/src/vespa/vespalib/util/fake_doom.cpp2
-rw-r--r--vespalib/src/vespa/vespalib/util/fake_doom.h4
5 files changed, 12 insertions, 4 deletions
diff --git a/vespalib/src/vespa/vespalib/util/clock.h b/vespalib/src/vespa/vespalib/util/clock.h
index 967bd07cbd4..1e37e3fff8d 100644
--- a/vespalib/src/vespa/vespalib/util/clock.h
+++ b/vespalib/src/vespa/vespalib/util/clock.h
@@ -8,7 +8,7 @@
namespace vespalib {
/**
- * Clock is a clock that updates the time at defined intervals.
+ * TODO Remove abstraction. Can use atomic ref directly
* It is intended used where you want to check the time with low cost, but where
* resolution is not that important.
*/
diff --git a/vespalib/src/vespa/vespalib/util/doom.cpp b/vespalib/src/vespa/vespalib/util/doom.cpp
index 227d43ee4c4..8fc82031e79 100644
--- a/vespalib/src/vespa/vespalib/util/doom.cpp
+++ b/vespalib/src/vespa/vespalib/util/doom.cpp
@@ -1,6 +1,7 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "doom.h"
+#include "fake_doom.h"
namespace vespalib {
@@ -12,4 +13,10 @@ Doom::Doom(const Clock &clock, steady_time softDoom,
_isExplicitSoftDoom(explicitSoftDoom)
{ }
+const Doom &
+Doom::never() noexcept {
+ static vespalib::FakeDoom neverExpire;
+ return neverExpire.get_doom();
+}
+
}
diff --git a/vespalib/src/vespa/vespalib/util/doom.h b/vespalib/src/vespa/vespalib/util/doom.h
index a175bbd20df..1d7070cedd0 100644
--- a/vespalib/src/vespa/vespalib/util/doom.h
+++ b/vespalib/src/vespa/vespalib/util/doom.h
@@ -19,6 +19,7 @@ public:
duration soft_left() const noexcept { return _softDoom - _clock.getTimeNS(); }
duration hard_left() const noexcept { return _hardDoom - _clock.getTimeNS(); }
bool isExplicitSoftDoom() const noexcept { return _isExplicitSoftDoom; }
+ static const Doom & never() noexcept;
private:
const Clock &_clock;
steady_time _softDoom;
diff --git a/vespalib/src/vespa/vespalib/util/fake_doom.cpp b/vespalib/src/vespa/vespalib/util/fake_doom.cpp
index 51318db135c..d9cbce0b152 100644
--- a/vespalib/src/vespa/vespalib/util/fake_doom.cpp
+++ b/vespalib/src/vespa/vespalib/util/fake_doom.cpp
@@ -4,7 +4,7 @@
namespace vespalib {
-FakeDoom::FakeDoom(steady_time::duration time_to_doom)
+FakeDoom::FakeDoom(steady_time::duration time_to_doom) noexcept
: _time(steady_clock::now()),
_clock(_time),
_doom(_clock, _clock.getTimeNS() + time_to_doom)
diff --git a/vespalib/src/vespa/vespalib/util/fake_doom.h b/vespalib/src/vespa/vespalib/util/fake_doom.h
index 78fc9d0f38a..1e6cfcb0c4d 100644
--- a/vespalib/src/vespa/vespalib/util/fake_doom.h
+++ b/vespalib/src/vespa/vespalib/util/fake_doom.h
@@ -15,8 +15,8 @@ class FakeDoom {
Clock _clock;
Doom _doom;
public:
- FakeDoom() : FakeDoom(1s) { }
- FakeDoom(steady_time::duration time_to_doom);
+ FakeDoom() noexcept : FakeDoom(1s) { }
+ FakeDoom(steady_time::duration time_to_doom) noexcept;
~FakeDoom();
const Doom& get_doom() const noexcept { return _doom; }
};