From c4e3b536fee8c2bfa67eec70eedf5ea0f0a4f60f Mon Sep 17 00:00:00 2001 From: fuzhufang Date: Wed, 12 Jun 2024 11:51:21 +0800 Subject: [PATCH] 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 --- evpp/EventLoop.h | 2 +- evpp/TcpServer.h | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/evpp/EventLoop.h b/evpp/EventLoop.h index d8e7f6470..40d24c256 100644 --- a/evpp/EventLoop.h +++ b/evpp/EventLoop.h @@ -241,7 +241,7 @@ typedef std::shared_ptr 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(); diff --git a/evpp/TcpServer.h b/evpp/TcpServer.h index 4c7c20fc6..7c9322ecd 100644 --- a/evpp/TcpServer.h +++ b/evpp/TcpServer.h @@ -32,7 +32,11 @@ class TcpServerEventLoopTmpl { } 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