lichao
2021-05-19 34cd75f77d0ca94dbdba4e6cc9451fe4d33e78b3
src/bh_util.h
@@ -18,6 +18,7 @@
#ifndef BH_UTIL_SOXWOK67
#define BH_UTIL_SOXWOK67
#include "macro.h"
#include <functional>
#include <mutex>
#include <stdint.h>
@@ -91,6 +92,8 @@
inline void PutInt(void *p, uint32_t u) { Put32(p, u); }
inline void PutInt(void *p, uint64_t u) { Put64(p, u); }
constexpr uint64_t MaskBits(int nbits) { return (uint64_t(1) << nbits) - 1; }
class ExitCall
{
   typedef std::function<void(void)> func_t;
@@ -154,9 +157,9 @@
   }
protected:
   static inline T &GetData()
   static inline T &GetData(const std::string &msg = "Must set data before use!")
   {
      if (!ptr()) { throw std::string("Must set ShmMsg shm before use!"); }
      if (!ptr()) { throw std::logic_error(msg); }
      return *ptr();
   }
@@ -167,13 +170,5 @@
      return ptr() ? false : Bind();
   }
};
// macro helper
#define JOIN_IMPL(a, b) a##b
#define JOIN(a, b) JOIN_IMPL(a, b)
// defer function / lambda.
#define DEFERF(func) ExitCall JOIN(defer_, __LINE__)(func)
// defer simple expression
#define DEFER1(expr) DEFERF([&]() { expr; })
#endif /* end of include guard: BH_UTIL_SOXWOK67 */