lichao
2021-06-03 b674aecae951c1f83e07f80956160fadf331d026
src/bh_util.h
@@ -41,8 +41,8 @@
inline void Put16(void *p, uint16_t u)
{
   auto ptr = static_cast<uint8_t *>(p);
   ptr[0] = (uint8_t)(u >> 8u);
   ptr[1] = (uint8_t)(u);
   ptr[0] = (uint8_t) (u >> 8u);
   ptr[1] = (uint8_t) (u);
}
inline uint32_t Get32(const void *p)
@@ -56,10 +56,10 @@
inline void Put32(void *p, uint32_t u)
{
   auto ptr = static_cast<uint8_t *>(p);
   ptr[0] = (uint8_t)(u >> 24u);
   ptr[1] = (uint8_t)(u >> 16u);
   ptr[2] = (uint8_t)(u >> 8u);
   ptr[3] = (uint8_t)(u);
   ptr[0] = (uint8_t) (u >> 24u);
   ptr[1] = (uint8_t) (u >> 16u);
   ptr[2] = (uint8_t) (u >> 8u);
   ptr[3] = (uint8_t) (u);
}
inline uint64_t Get64(const void *p)
@@ -77,14 +77,14 @@
inline void Put64(void *p, uint64_t u)
{
   auto ptr = static_cast<uint8_t *>(p);
   ptr[0] = (uint8_t)(u >> 56);
   ptr[1] = (uint8_t)(u >> 48);
   ptr[2] = (uint8_t)(u >> 40u);
   ptr[3] = (uint8_t)(u >> 32);
   ptr[4] = (uint8_t)(u >> 24u);
   ptr[5] = (uint8_t)(u >> 16u);
   ptr[6] = (uint8_t)(u >> 8u);
   ptr[7] = (uint8_t)(u);
   ptr[0] = (uint8_t) (u >> 56);
   ptr[1] = (uint8_t) (u >> 48);
   ptr[2] = (uint8_t) (u >> 40u);
   ptr[3] = (uint8_t) (u >> 32);
   ptr[4] = (uint8_t) (u >> 24u);
   ptr[5] = (uint8_t) (u >> 16u);
   ptr[6] = (uint8_t) (u >> 8u);
   ptr[7] = (uint8_t) (u);
}
inline void PutInt(void *p, uint8_t u) { Put8(p, u); }
@@ -143,31 +143,6 @@
   {
      Lock lk(mutex_);
      return f(data_);
   }
};
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(const std::string &msg = "Must set data before use!")
   {
      if (!ptr()) { throw std::logic_error(msg); }
      return *ptr();
   }
public:
   static bool SetData(T &t)
   {
      auto Bind = [&]() { ptr() = &t; return true; };
      return ptr() ? false : Bind();
   }
};