浏览代码

Avoid repeated EventLoopThread::start

ithewei 1 年之前
父节点
当前提交
b350201209
共有 2 个文件被更改,包括 4 次插入1 次删除
  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