summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Donnelly <pdonnell@redhat.com>2021-02-20 04:18:25 +0100
committerPatrick Donnelly <pdonnell@redhat.com>2021-03-19 16:52:54 +0100
commitb158ee04f9e75b9a9c9d4f46e297b80319689754 (patch)
tree858bc1199dc2667db0f5905b28bae14a0562c451
parentRevert "libradosstriper: add function to read into char*" (diff)
downloadceph-b158ee04f9e75b9a9c9d4f46e297b80319689754.tar.xz
ceph-b158ee04f9e75b9a9c9d4f46e297b80319689754.zip
common: add timeval conversion for durations
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
-rw-r--r--src/common/ceph_time.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/common/ceph_time.h b/src/common/ceph_time.h
index 2f99188e439..92048029274 100644
--- a/src/common/ceph_time.h
+++ b/src/common/ceph_time.h
@@ -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,