From d415d383db1e1cf8038ffb34459864e3b6e19f39 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 10 Jun 2017 12:50:25 +0200 Subject: minor cleanup only --- compat/time.hpp | 8 +++++--- compat/timer.hpp | 16 +++++++++++++++- compat/util.hpp | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) (limited to 'compat') diff --git a/compat/time.hpp b/compat/time.hpp index b560da70..c07f29cb 100644 --- a/compat/time.hpp +++ b/compat/time.hpp @@ -1,10 +1,12 @@ #pragma once +#include "compat/functional.hpp" + #include namespace time_units { -template +template> using duration = std::chrono::duration; template @@ -13,8 +15,8 @@ static inline constexpr auto time_cast(const u& in) return std::chrono::duration_cast(in); } -using secs = duration>; -using secs_ = duration>; +using secs = duration; +using secs_ = duration; using ms = duration; using ms_ = duration; using us = duration; diff --git a/compat/timer.hpp b/compat/timer.hpp index 6af7430d..ac255a9d 100644 --- a/compat/timer.hpp +++ b/compat/timer.hpp @@ -20,6 +20,7 @@ #include #include "time.hpp" +#include "util.hpp" class OTR_COMPAT_EXPORT Timer final { @@ -43,7 +44,20 @@ public: t elapsed() const { using namespace time_units; - return static_cast(ns(elapsed_nsecs())); + return time_cast(ns(elapsed_nsecs())); + } + + template + bool is_elapsed(const t& time_value) + { + using namespace time_units; + + if (unlikely(elapsed() >= time_value)) + { + start(); + return true; + } + return false; } long long elapsed_nsecs() const; diff --git a/compat/util.hpp b/compat/util.hpp index 823b83d1..3a53e203 100644 --- a/compat/util.hpp +++ b/compat/util.hpp @@ -12,7 +12,7 @@ #include #include -#define progn(...) ([&]() { __VA_ARGS__ }()) +#define progn(...) (([&]() { __VA_ARGS__ })()) #define prog1(x, ...) (([&]() { auto _ret1324 = (x); do { __VA_ARGS__; } while (0); return _ret1324; })()) #define once_only(...) progn(static bool once = false; if (!once) { once = true; __VA_ARGS__; }) -- cgit v1.2.3