diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-04-20 22:32:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-20 22:32:21 +0200 |
commit | b327b31171346530a08e3acc88e36fd158e0f94d (patch) | |
tree | 13da774f996a2c85a7cb86386d13c3203832c623 /vespalib | |
parent | 01394bbefc7e8376cb59ac2fe24f752b5c22b0bd (diff) | |
parent | a4f18f133b2b9032d41246c27f1186a5b9b55346 (diff) |
Merge pull request #12988 from vespa-engine/balder/use-system-independent-xxx_clock
There are so many combinations that the libstdc++ library can be buil…
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/util/time.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/vespalib/src/vespa/vespalib/util/time.cpp b/vespalib/src/vespa/vespalib/util/time.cpp index 46cf4806dfc..2e8f4e7e30e 100644 --- a/vespalib/src/vespa/vespalib/util/time.cpp +++ b/vespalib/src/vespa/vespalib/util/time.cpp @@ -52,3 +52,29 @@ Timer::waitAtLeast(duration dur, bool busyWait) { } } + +namespace std::chrono { + +// This is a hack to avoid the slow clock computations on RHEL7/CentOS 7 due to using systemcalls. +// This brings cost down from 550-560ns to 18-19ns + +inline namespace _V2 { + +system_clock::time_point +system_clock::now() noexcept { + timespec tp; + clock_gettime(CLOCK_REALTIME, &tp); + return time_point(duration(chrono::seconds(tp.tv_sec) + + chrono::nanoseconds(tp.tv_nsec))); +} + +steady_clock::time_point +steady_clock::now() noexcept { + timespec tp; + clock_gettime(CLOCK_MONOTONIC, &tp); + return time_point(duration(chrono::seconds(tp.tv_sec) + + chrono::nanoseconds(tp.tv_nsec))); +} + +} +} |