diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-03-03 12:42:29 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-03-03 12:42:29 +0000 |
commit | e8e2333dcd6a5ce8bd251834890ee27ff37680c1 (patch) | |
tree | e63940b7e212263082f874779970a2eefd96f1cb /staging_vespalib | |
parent | 64c08801e0ac5094fb111c5fe3ea63cc7597506d (diff) |
Add missing TestClock
Diffstat (limited to 'staging_vespalib')
-rw-r--r-- | staging_vespalib/src/vespa/vespalib/util/testclock.cpp | 16 | ||||
-rw-r--r-- | staging_vespalib/src/vespa/vespalib/util/testclock.h | 32 |
2 files changed, 48 insertions, 0 deletions
diff --git a/staging_vespalib/src/vespa/vespalib/util/testclock.cpp b/staging_vespalib/src/vespa/vespalib/util/testclock.cpp new file mode 100644 index 00000000000..3f14a173a39 --- /dev/null +++ b/staging_vespalib/src/vespa/vespalib/util/testclock.cpp @@ -0,0 +1,16 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "testclock.h" +#include <vespa/vespalib/util/invokeserviceimpl.h> + +namespace vespalib { + +TestClock::TestClock() + : _ticker(std::make_unique<InvokeServiceImpl>(10ms)), + _clock(_ticker->nowPtr()) +{ +} + +TestClock::~TestClock() = default; + +} diff --git a/staging_vespalib/src/vespa/vespalib/util/testclock.h b/staging_vespalib/src/vespa/vespalib/util/testclock.h new file mode 100644 index 00000000000..54e9f1efb6a --- /dev/null +++ b/staging_vespalib/src/vespa/vespalib/util/testclock.h @@ -0,0 +1,32 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#pragma once + +#include "clock.h" + +namespace vespalib { + +class InvokeServiceImpl; + +/** + * Clock is a clock that updates the time at defined intervals. + * It is intended used where you want to check the time with low cost, but where + * resolution is not that important. + */ + +class TestClock +{ +private: + std::unique_ptr<InvokeServiceImpl> _ticker; + Clock _clock; +public: + TestClock(); + TestClock(const TestClock &) = delete; + TestClock & operator =(const TestClock &) = delete; + TestClock(TestClock &&) = delete; + TestClock & operator =(TestClock &&) = delete; + ~TestClock(); + const Clock & clock() { return _clock; } +}; + +} + |