]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common: Add maybe_timespan
authorAdam C. Emerson <aemerson@redhat.com>
Thu, 17 Aug 2017 00:42:00 +0000 (20:42 -0400)
committerAdam C. Emerson <aemerson@redhat.com>
Fri, 15 May 2020 14:55:10 +0000 (10:55 -0400)
For handling the common idiom of a zero timeout.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/common/ceph_time.h

index f6185c882006312228c3a78ce8837fe0db758b62..58b1550495d864e7f456b75b96506a239b2feeff 100644 (file)
@@ -18,6 +18,7 @@
 #include <chrono>
 #include <iostream>
 #include <string>
+#include <optional>
 #include <sys/time.h>
 
 #include "include/ceph_assert.h"
@@ -434,6 +435,9 @@ namespace ceph {
       return std::chrono::duration_cast<timespan>(
        std::chrono::duration<double>(d));
     }
+    inline std::optional<timespan> maybe_timespan(const double d) {
+      return d ? std::make_optional(make_timespan(d)) : std::nullopt;
+    }
   }
 
   std::ostream& operator<<(std::ostream& m, const timespan& t);