From 1fbfef2a51db4a3bac9d8a5b87af94a40a913b7a Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期日, 25 四月 2021 15:33:40 +0800 Subject: [PATCH] change mqid from uuid to uint64. --- src/bh_util.h | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-) diff --git a/src/bh_util.h b/src/bh_util.h index e3ab70b..c419a59 100644 --- a/src/bh_util.h +++ b/src/bh_util.h @@ -143,6 +143,31 @@ } }; +template <class T, class Tag> +class StaticDataRef +{ + typedef T *Ptr; + static inline Ptr &ptr() + { + static Ptr sp(nullptr); + return sp; + } + +protected: + static inline T &GetData() + { + if (!ptr()) { throw std::string("Must set ShmMsg shm before use!"); } + return *ptr(); + } + +public: + static bool SetData(T &t) + { + auto Bind = [&]() { ptr() = &t; return true; }; + return ptr() ? false : Bind(); + } +}; + // macro helper #define JOIN_IMPL(a, b) a##b #define JOIN(a, b) JOIN_IMPL(a, b) -- Gitblit v1.8.0