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/msg.h |   24 +++---------------------
 1 files changed, 3 insertions(+), 21 deletions(-)

diff --git a/src/msg.h b/src/msg.h
index 6ce4902..e332a5d 100644
--- a/src/msg.h
+++ b/src/msg.h
@@ -23,7 +23,6 @@
 #include "shm.h"
 #include <atomic>
 #include <boost/interprocess/offset_ptr.hpp>
-#include <boost/uuid/uuid_generators.hpp>
 #include <functional>
 #include <stdint.h>
 
@@ -34,11 +33,10 @@
 // ShmMsg is safe to be stored in shared memory, so POD data or offset_ptr is required.
 // message content layout: (meta) / header_size + header + data_size + data
 
-typedef boost::uuids::uuid MQId;
-
-class ShmMsg
+class ShmMsg : private StaticDataRef<SharedMemory, ShmMsg>
 {
 private:
+	static inline SharedMemory &shm() { return GetData(); }
 	// store ref count, msgs shareing the same data should also hold a pointer of the same RefCount object.
 	class RefCount : private boost::noncopyable
 	{
@@ -58,16 +56,6 @@
 	{
 		static const Offset base = Addr(shm().get_address()); // cache value.
 		return base;
-	}
-	static inline SharedMemory &shm()
-	{
-		if (!pshm()) { throw std::string("Must set ShmMsg shm before use!"); }
-		return *pshm();
-	}
-	static inline SharedMemory *&pshm()
-	{
-		static SharedMemory *pshm = 0;
-		return pshm;
 	}
 
 	static const uint32_t kMsgTag = 0xf1e2d3c4;
@@ -145,13 +133,7 @@
 	T *get() const { return static_cast<T *>(Ptr(offset_ + BaseAddr())); }
 
 public:
-	static bool BindShm(SharedMemory &shm)
-	{
-		assert(!pshm());
-		pshm() = &shm;
-		return true;
-	}
-
+	static bool BindShm(SharedMemory &shm) { return SetData(shm); }
 	ShmMsg() :
 	    ShmMsg(nullptr) {}
 	explicit ShmMsg(const size_t size) :

--
Gitblit v1.8.0