From 94d1155e8ac667ebf2ffa47c063410c4b051cdfe Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Tue, 8 May 2018 15:06:10 -0400 Subject: [PATCH] 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) --- src/common/ceph_time.h | 14 ++++++++++++++ src/include/encoding.h | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/common/ceph_time.h b/src/common/ceph_time.h index 73a11eef6b72c..a9f9195d371b7 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 a13393ccfd420..187c174a1e607 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; -- 2.39.5