Skip to content

Commit

Permalink
Add namespace for currentThreadEventLoop and when there is no worker …
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
fuzhufang and grass authored Jun 12, 2024
1 parent a56fc78 commit c4e3b53
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion evpp/EventLoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion evpp/TcpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c4e3b53

Please sign in to comment.