浏览代码

Add namespace for currentThreadEventLoop and when there is no worker thread loop, acceptor_loop should also be returned (#568)

* when there is no worker thread loop, acceptor_loop should also be returned

* add namespace for currentThreadEventLoop

---------

Co-authored-by: grass <fuzhufang@163.com>
fuzhufang 1 年之前
父节点
当前提交
c4e3b536fe
共有 2 个文件被更改,包括 6 次插入2 次删除
  1. 1 1
      evpp/EventLoop.h
  2. 5 1
      evpp/TcpServer.h

+ 1 - 1
evpp/EventLoop.h

@@ -241,7 +241,7 @@ typedef std::shared_ptr<EventLoop> EventLoopPtr;
 static inline EventLoop* tlsEventLoop() {
     return (EventLoop*)ThreadLocalStorage::get(ThreadLocalStorage::EVENT_LOOP);
 }
-#define currentThreadEventLoop tlsEventLoop()
+#define currentThreadEventLoop ::hv::tlsEventLoop()
 
 static inline TimerID setTimer(int timeout_ms, TimerCallback cb, uint32_t repeat = INFINITE) {
     EventLoop* loop = tlsEventLoop();

+ 5 - 1
evpp/TcpServer.h

@@ -32,7 +32,11 @@ public:
     }
 
     EventLoopPtr loop(int idx = -1) {
-        return worker_threads.loop(idx);
+        EventLoopPtr worker_loop = worker_threads.loop(idx);
+        if (worker_loop == NULL) {
+            worker_loop = acceptor_loop;
+        }
+        return worker_loop;
     }
 
     //@retval >=0 listenfd, <0 error