From 628c1c21ffb19d8c96ed9ce89531595f9870ab1a Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期五, 23 四月 2021 18:41:02 +0800 Subject: [PATCH] add msg tag; recv all msgs before remove mq. --- src/msg.h | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/msg.h b/src/msg.h index 99b3a09..6ce4902 100644 --- a/src/msg.h +++ b/src/msg.h @@ -70,9 +70,11 @@ return pshm; } - struct Meta { + static const uint32_t kMsgTag = 0xf1e2d3c4; + typedef struct { RefCount count_; - }; + const uint32_t tag_ = kMsgTag; + } Meta; Offset offset_; void *Alloc(const size_t size) { @@ -155,9 +157,8 @@ explicit ShmMsg(const size_t size) : ShmMsg(Alloc(size)) {} void swap(ShmMsg &a) { std::swap(offset_, a.offset_); } - bool valid() const { return static_cast<bool>(offset_); } + bool valid() const { return static_cast<bool>(offset_) && meta()->tag_ == kMsgTag; } - // AddRef and Release works for both counted and not counted msg. int AddRef() const { return valid() ? meta()->count_.Inc() : 1; } int Release() { -- Gitblit v1.8.0