From c6964d5af25d4ec7ed9dbe7674dc4e3896b36ead Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期五, 16 四月 2021 16:10:02 +0800 Subject: [PATCH] node remove mq if never registered; refactor. --- src/sendq.cpp | 24 +++++++----------------- 1 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/sendq.cpp b/src/sendq.cpp index 3f988ca..ad293c3 100644 --- a/src/sendq.cpp +++ b/src/sendq.cpp @@ -19,24 +19,13 @@ #include "shm_queue.h" #include <chrono> +//TODO change to save head, body, instead of MsgI. +// as MsgI which is in shm, but head, body are in current process. +// Then if node crashes, shm will not be affected by msgs in sendq. +// but pulishing ref-counted msg need some work. + int SendQ::DoSend1Remote(bhome_shm::ShmMsgQueue &mq, const Remote &remote, Array &arr) { - static size_t total = 0; - static size_t count = 0; - static size_t max_len = 0; - static time_t last = 0; - ++count; - total += arr.size(); - if (arr.size() > max_len) { - max_len = arr.size(); - } - time_t now; - time(&now); - if (now > last && count > 0) { - last = now; - printf("avg size : %ld, max size: %ld\n", total / count, max_len); - } - auto FirstNotExpired = [](Array &l) { auto Less = [](const TimedMsg &msg, const TimePoint &tp) { return msg.expire() < tp; }; return std::lower_bound(l.begin(), l.end(), Now(), Less); @@ -77,6 +66,7 @@ bool SendQ::TrySend(bhome_shm::ShmMsgQueue &mq) { + std::unique_lock<std::mutex> lock(mutex_out_); size_t nsend = 0; if (!out_.empty()) { auto rec = out_.begin(); @@ -91,7 +81,7 @@ } auto Collect = [&]() { - std::unique_lock<std::mutex> lock(mutex_); + std::unique_lock<std::mutex> lock(mutex_in_); if (out_.empty()) { out_.swap(in_); } else if (nsend == 0) { // remote blocked -- Gitblit v1.8.0