From: Xinze Chi Date: Mon, 14 Dec 2015 16:29:14 +0000 (+0800) Subject: common: utime_t encoding optimization X-Git-Tag: v10.0.3~206^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a977e39f042c835b4d194592d7c0b213eb510c22;p=ceph.git common: utime_t encoding optimization there is no padding between tv_sec and tv_nsec, no matter 32-bit or 64-bit machine. Signed-off-by: Xinze Chi --- diff --git a/src/include/utime.h b/src/include/utime.h index 27241e0b324..a60501a63fa 100644 --- a/src/include/utime.h +++ b/src/include/utime.h @@ -28,6 +28,11 @@ // -------- // utime_t +/* WARNING: If add member in utime_t, please make sure the encode/decode funtion + * work well. For little-endian machine, we should make sure there is no padding + * in 32-bit machine and 64-bit machine. + * You should also modify the padding_check function. + */ class utime_t { public: struct { @@ -95,14 +100,29 @@ public: tv.tv_sec = v->tv_sec; tv.tv_nsec = v->tv_usec*1000; } - + void padding_check() { + static_assert( + sizeof(utime_t) == + sizeof(tv.tv_sec) + + sizeof(tv.tv_nsec) + , + "utime_t have padding"); + } void encode(bufferlist &bl) const { +#if defined(CEPH_LITTLE_ENDIAN) + bl.append((char *)(this), sizeof(__u32) + sizeof(__u32)); +#else ::encode(tv.tv_sec, bl); ::encode(tv.tv_nsec, bl); +#endif } void decode(bufferlist::iterator &p) { +#if defined(CEPH_LITTLE_ENDIAN) + p.copy(sizeof(__u32) + sizeof(__u32), (char *)(this)); +#else ::decode(tv.tv_sec, p); ::decode(tv.tv_nsec, p); +#endif } void encode_timeval(struct ceph_timespec *t) const {