From: Patrick Donnelly Date: Sat, 20 Feb 2021 03:18:25 +0000 (-0800) Subject: common: add timeval conversion for durations X-Git-Tag: v16.2.0~36^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8c9502d03f010991a616c3a159ea339e6266f574;p=ceph.git common: add timeval conversion for durations Signed-off-by: Patrick Donnelly (cherry picked from commit b158ee04f9e75b9a9c9d4f46e297b80319689754) --- 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 signedspan; +template +struct timeval to_timeval(Duration d) { + struct timeval tv; + auto sec = std::chrono::duration_cast(d); + tv.tv_sec = sec.count(); + auto usec = std::chrono::duration_cast(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,