From 6b96ee857e366af317ab9dc1b6b4f9c22576e83b Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期四, 20 五月 2021 17:12:34 +0800 Subject: [PATCH] add sleeper, to reduce cpu usage. --- src/topic_node.cpp | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/topic_node.cpp b/src/topic_node.cpp index 8bbb929..6ed7713 100644 --- a/src/topic_node.cpp +++ b/src/topic_node.cpp @@ -17,6 +17,7 @@ */ #include "topic_node.h" #include "bh_util.h" +#include "sleeper.h" #include <chrono> #include <list> @@ -51,7 +52,6 @@ TopicNode::~TopicNode() { - LOG_DEBUG() << "~TopicNode()"; Stop(); } @@ -140,9 +140,7 @@ } void TopicNode::Stop() { - LOG_DEBUG() << "Node Stopping"; for (auto &p : sockets_) { p->Stop(); } - LOG_INFO() << "Node Stopped"; } bool TopicNode::Register(ProcInfo &proc, MsgCommonReply &reply_body, const int timeout_ms) @@ -399,10 +397,11 @@ } BHMsgHead head; std::string body; + FibUSleeper sleeper(1000 * 10); auto end_time = steady_clock::now() + milliseconds(timeout_ms); while (!server_buffer_->Read(head, body)) { if (steady_clock::now() < end_time) { - robust::QuickSleep(); + sleeper.Sleep(); } else { return false; } @@ -677,10 +676,11 @@ BHMsgHead head; std::string body; + FibUSleeper sleeper(1000 * 10); auto end_time = steady_clock::now() + milliseconds(timeout_ms); while (!sub_buffer_->Read(head, body)) { if (steady_clock::now() < end_time) { - robust::QuickSleep(); + sleeper.Sleep(); } else { return false; } -- Gitblit v1.8.0