]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: add timeval conversion for durations
authorPatrick Donnelly <pdonnell@redhat.com>
Sat, 20 Feb 2021 03:18:25 +0000 (19:18 -0800)
committerPatrick Donnelly <pdonnell@redhat.com>
Fri, 19 Mar 2021 15:52:54 +0000 (08:52 -0700)
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
src/common/ceph_time.h

index 2f99188e439b474ed8dc004e406d960b09951ed0..9204802927407eb05b8e06c41e925baa933b4eba 100644 (file)
@@ -64,6 +64,16 @@ typedef int64_t signed_rep;
 // differences between now and a time point in the past.
 typedef std::chrono::duration<signed_rep, std::nano> signedspan;
 
+template<typename Duration>
+struct timeval to_timeval(Duration d) {
+  struct timeval tv;
+  auto sec = std::chrono::duration_cast<std::chrono::seconds>(d);
+  tv.tv_sec = sec.count();
+  auto usec = std::chrono::duration_cast<std::chrono::microseconds>(d-sec);
+  tv.tv_usec = usec.count();
+  return tv;
+}
+
 // We define our own clocks so we can have our choice of all time
 // sources supported by the operating system. With the standard
 // library the resolution and cost are unspecified. (For example,