From: Casey Bodley Date: Tue, 8 May 2018 19:06:10 +0000 (-0400) Subject: encoding: constrain the time_point templates X-Git-Tag: v13.2.3~122^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=94d1155e8ac667ebf2ffa47c063410c4b051cdfe;p=ceph.git encoding: constrain the time_point templates disable use of encode/decode for time_points that don't provide conversions to/from timespec. these are only intended for use by real_clock and coarse_real_clock Signed-off-by: Casey Bodley (cherry picked from commit 427655e39180640fb1de56cef13c4ed8c34fa3bb) --- diff --git a/src/common/ceph_time.h b/src/common/ceph_time.h index 73a11eef6b7..a9f9195d371 100644 --- a/src/common/ceph_time.h +++ b/src/common/ceph_time.h @@ -476,6 +476,20 @@ inline timespan to_timespan(signedspan z) { ceph_assert(z >= signedspan::zero()); return std::chrono::duration_cast(z); } + +// detects presence of Clock::to_timespec() and from_timespec() +template > +struct converts_to_timespec : std::false_type {}; + +template +struct converts_to_timespec())) + )>> : std::true_type {}; + +template +constexpr bool converts_to_timespec_v = converts_to_timespec::value; + } // namespace ceph #endif // COMMON_CEPH_TIME_H diff --git a/src/include/encoding.h b/src/include/encoding.h index a13393ccfd4..187c174a1e6 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -280,7 +280,8 @@ inline void decode_nohead(int len, bufferlist& s, bufferlist::iterator& p) // Time, since the templates are defined in std::chrono -template +template>* = nullptr> void encode(const std::chrono::time_point& t, ceph::bufferlist &bl) { auto ts = Clock::to_timespec(t); @@ -291,7 +292,8 @@ void encode(const std::chrono::time_point& t, encode(ns, bl); } -template +template>* = nullptr> void decode(std::chrono::time_point& t, bufferlist::iterator& p) { uint32_t s;