From 58d904a328c0d849769b483e901a0be9426b8209 Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期二, 20 七月 2021 20:20:44 +0800 Subject: [PATCH] 调整Request C.BHFree的位置 --- src/robust.h | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/robust.h b/src/robust.h index c46010a..255aea4 100644 --- a/src/robust.h +++ b/src/robust.h @@ -21,6 +21,7 @@ #include "bh_util.h" #include "log.h" +#include <string.h> #include <atomic> #include <chrono> #include <unistd.h> @@ -54,7 +55,7 @@ static inline Data Dec(const Data d) { return d >> 1; } // lowest bit 1 means data ok. typedef std::atomic<Data> AData; - static_assert(sizeof(Data) == sizeof(AData)); + // static_assert(sizeof(Data) == sizeof(AData)); AData buf; }; @@ -67,6 +68,8 @@ typedef std::function<Data(const Data)> Handler; bool ClientRequest(const Data request, Data &reply); bool ServerProcess(Handler onReq); + AtomicReqRep() : + data_(0), timestamp_(now()) {} private: enum State { @@ -79,7 +82,7 @@ static Data Decode(Data d) { return d >> 3; } typedef std::chrono::steady_clock steady_clock; typedef steady_clock::duration Duration; - Duration now() { return steady_clock::now().time_since_epoch(); } + static Duration now() { return steady_clock::now().time_since_epoch(); } bool DataCas(Data expected, Data val) { return data_.compare_exchange_strong(expected, val); } std::atomic<Data> data_; -- Gitblit v1.8.0