From 3931f83205f153f2bc7fc36d1a894cdc3f14b4db Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期三, 21 四月 2021 16:52:51 +0800 Subject: [PATCH] change node socket to vector; try lock free queue. --- src/sendq.cpp | 35 +++++++++++++++++++++++++++-------- 1 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/sendq.cpp b/src/sendq.cpp index 242f8de..4be24f1 100644 --- a/src/sendq.cpp +++ b/src/sendq.cpp @@ -30,22 +30,41 @@ for (auto it = arr.begin(); it != pos; ++it) { auto &info = it->data(); if (info.on_expire_) { - info.on_expire_(info.msg_); + info.on_expire_(info.data_); } - info.msg_.Release(mq.shm()); + if (info.data_.index() == 0) { + boost::variant2::get<0>(info.data_).Release(mq.shm()); + } } - int n = mq.TrySendAll(*(MQId *) remote.data(), MsgIter(pos), MsgIter(arr.end())); - for (int i = 0; i < n; ++i) { - auto &msg = pos->data().msg_; - if (msg.IsCounted()) { - msg.Release(mq.shm()); + auto SendData = [&](Data &d) { + bool r = false; + if (d.index() == 0) { + auto &msg = boost::variant2::get<0>(pos->data().data_); + r = mq.TrySend(*(MQId *) remote.data(), msg); + if (r && msg.IsCounted()) { + msg.Release(mq.shm()); + } + } else { + auto &content = boost::variant2::get<1>(pos->data().data_); + MsgI msg; + if (msg.Make(mq.shm(), content)) { + r = mq.TrySend(*(MQId *) remote.data(), msg); + if (!r || msg.IsCounted()) { + msg.Release(mq.shm()); + } + } } + return r; + }; + + while (pos != arr.end() && SendData(pos->data().data_)) { ++pos; } + int nprocessed = std::distance(arr.begin(), pos); arr.erase(arr.begin(), pos); - return n; + return nprocessed; } int SendQ::DoSend1Remote(bhome_shm::ShmMsgQueue &mq, const Remote &remote, ArrayList &al) -- Gitblit v1.8.0