aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp
diff options
context:
space:
mode:
authorGravatar vjpai <vpai@google.com>2015-06-02 13:58:44 -0700
committerGravatar vjpai <vpai@google.com>2015-06-02 13:58:44 -0700
commit3beb20c3e2eb0aeb4a96bf671243e4d5d2158fb4 (patch)
tree1b8df14bd7eafcb9e9c59efa919d961c0424f61b /src/cpp
parent924d459c271acb6cf940da8183bcb8eaacb6b662 (diff)
Support use of high_res clock in timepoints
Diffstat (limited to 'src/cpp')
-rw-r--r--src/cpp/util/time.cc15
1 files changed, 15 insertions, 0 deletions
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<seconds>(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<nanoseconds>(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();