Browse Source

Avoid repeated EventLoopThread::start

ithewei 1 year ago
parent
commit
b350201209
2 changed files with 4 additions and 1 deletions
  1. 1 0
      evpp/EventLoopThread.h
  2. 3 1
      evpp/TcpServer.h

+ 1 - 0
evpp/EventLoopThread.h

@@ -44,6 +44,7 @@ public:
                Functor pre = Functor(),
                Functor post = Functor()) {
         if (status() >= kStarting && status() < kStopped) return;
+        if (isRunning()) return;
         setStatus(kStarting);
 
         thread_ = std::make_shared<std::thread>(&EventLoopThread::loop_thread, this, pre, post);

+ 3 - 1
evpp/TcpServer.h

@@ -298,7 +298,9 @@ public:
     // start thread-safe
     void start(bool wait_threads_started = true) {
         TcpServerEventLoopTmpl<TSocketChannel>::start(wait_threads_started);
-        EventLoopThread::start(wait_threads_started);
+        if (!isRunning()) {
+            EventLoopThread::start(wait_threads_started);
+        }
     }
 
     // stop thread-safe