From 3beb20c3e2eb0aeb4a96bf671243e4d5d2158fb4 Mon Sep 17 00:00:00 2001 From: vjpai Date: Tue, 2 Jun 2015 13:58:44 -0700 Subject: Support use of high_res clock in timepoints --- src/cpp/util/time.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/cpp') diff --git a/src/cpp/util/time.cc b/src/cpp/util/time.cc index 1fef2a56de..83292e9338 100644 --- a/src/cpp/util/time.cc +++ b/src/cpp/util/time.cc @@ -42,6 +42,7 @@ using std::chrono::duration_cast; using std::chrono::nanoseconds; using std::chrono::seconds; using std::chrono::system_clock; +using std::chrono::high_resolution_clock; namespace grpc { @@ -59,6 +60,20 @@ void Timepoint2Timespec(const system_clock::time_point& from, to->tv_nsec = nsecs.count(); } +void Timepoint2Timespec(const high_resolution_clock::time_point& from, + gpr_timespec* to) { + high_resolution_clock::duration deadline = from.time_since_epoch(); + seconds secs = duration_cast(deadline); + if (from == high_resolution_clock::time_point::max() || + secs.count() >= gpr_inf_future.tv_sec || secs.count() < 0) { + *to = gpr_inf_future; + return; + } + nanoseconds nsecs = duration_cast(deadline - secs); + to->tv_sec = secs.count(); + to->tv_nsec = nsecs.count(); +} + system_clock::time_point Timespec2Timepoint(gpr_timespec t) { if (gpr_time_cmp(t, gpr_inf_future) == 0) { return system_clock::time_point::max(); -- cgit v1.2.3