]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
include: utime_t can convert from ceph::coarse_real_time
authorCasey Bodley <cbodley@redhat.com>
Tue, 8 May 2018 17:04:17 +0000 (13:04 -0400)
committerNathan Cutler <ncutler@suse.com>
Tue, 2 Oct 2018 17:20:00 +0000 (19:20 +0200)
instead of accepting ceph::real_time directly, the converting
constructor takes a std::chrono::time_point<Clock>, constrained to
clocks that support timespec conversions. this currently just means
ceph::real_time and ceph::coarse_real_time

Signed-off-by: Casey Bodley <cbodley@redhat.com>
(cherry picked from commit 61fb24883e812c11016acea0654f6aef7ddab1f7)

src/include/utime.h

index 7f6c2460b779a144a2940258eed7c21669c5363f..92783bb9417689b5aceb00e374c43b189ae0b948 100644 (file)
@@ -71,10 +71,12 @@ public:
     tv.tv_sec = v.tv_sec;
     tv.tv_nsec = v.tv_nsec;
   }
-  explicit utime_t(const ceph::real_time& rt) {
-    ceph_timespec ts = real_clock::to_ceph_timespec(rt);
-    decode_timeval(&ts);
-  }
+  // conversion from ceph::real_time/coarse_real_time
+  template <typename Clock, typename std::enable_if_t<
+            ceph::converts_to_timespec_v<Clock>>* = nullptr>
+  explicit utime_t(const std::chrono::time_point<Clock>& t)
+    : utime_t(Clock::to_timespec(t)) {} // forward to timespec ctor
+
   utime_t(const struct timeval &v) {
     set_from_timeval(&v);
   }