From af86015d724e5edf001aa024fe7d8581c45cffd9 Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期四, 15 四月 2021 10:44:12 +0800 Subject: [PATCH] fix sendq lock, use different mutexes for in,out. --- src/sendq.cpp | 19 ++----------------- 1 files changed, 2 insertions(+), 17 deletions(-) diff --git a/src/sendq.cpp b/src/sendq.cpp index 3f988ca..242f8de 100644 --- a/src/sendq.cpp +++ b/src/sendq.cpp @@ -21,22 +21,6 @@ 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 +61,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 +76,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