From b350201209e12090dee7a0c812546e95b2af3caa Mon Sep 17 00:00:00 2001 From: ithewei Date: Fri, 19 Jul 2024 19:43:57 +0800 Subject: [PATCH] Avoid repeated EventLoopThread::start --- evpp/EventLoopThread.h | 1 + evpp/TcpServer.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/evpp/EventLoopThread.h b/evpp/EventLoopThread.h index 47f20db50..51b87b9cc 100644 --- a/evpp/EventLoopThread.h +++ b/evpp/EventLoopThread.h @@ -44,6 +44,7 @@ class EventLoopThread : public Status { Functor pre = Functor(), Functor post = Functor()) { if (status() >= kStarting && status() < kStopped) return; + if (isRunning()) return; setStatus(kStarting); thread_ = std::make_shared(&EventLoopThread::loop_thread, this, pre, post); diff --git a/evpp/TcpServer.h b/evpp/TcpServer.h index 7c9322ecd..df6a932c6 100644 --- a/evpp/TcpServer.h +++ b/evpp/TcpServer.h @@ -298,7 +298,9 @@ class TcpServerTmpl : private EventLoopThread, public TcpServerEventLoopTmpl::start(wait_threads_started); - EventLoopThread::start(wait_threads_started); + if (!isRunning()) { + EventLoopThread::start(wait_threads_started); + } } // stop thread-safe