From 7ea018a87528ed0b9eeb2cb57f569153a3cc9515 Mon Sep 17 00:00:00 2001 From: baigao-X <1007668733@qq.com> Date: Thu, 4 Jan 2024 19:00:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AF=B9event=5Fcache=5Fexpi?= =?UTF-8?q?red=5Fmap=20=E6=8F=92=E5=85=A5=E5=92=8C=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E4=B8=8D=E5=90=88=E7=90=86=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Poller/EventPoller.cpp | 20 ++++++++++---------- src/Poller/EventPoller.h | 5 ----- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/Poller/EventPoller.cpp b/src/Poller/EventPoller.cpp index 3d742019..d003635e 100644 --- a/src/Poller/EventPoller.cpp +++ b/src/Poller/EventPoller.cpp @@ -147,15 +147,19 @@ int EventPoller::delEvent(int fd, PollCompleteCB cb) { if (isCurrentThread()) { #if defined(HAS_EPOLL) bool success = epoll_ctl(_epoll_fd, EPOLL_CTL_DEL, fd, nullptr) == 0 && _event_map.erase(fd) > 0; - refreshEventCache(fd); + if (success) { + _event_cache_expired_map[fd] = true; + } cb(success); return success ? 0 : -1; #else - cb(_event_map.erase(fd)); - refreshEventCache(fd); + bool success = _event_map.erase(fd); + if (success) { + _event_cache_expired_map[fd] = true; + } + cb(success); return 0; #endif //HAS_EPOLL - } //跨线程操作 @@ -312,7 +316,7 @@ void EventPoller::runLoop(bool blocked, bool ref_self) { for (int i = 0; i < ret; ++i) { struct epoll_event &ev = events[i]; int fd = ev.data.fd; - if (_event_cache_expired_map[fd]) { + if (_event_cache_expired_map.find(fd) != _event_cache_expired_map.end()) { //event cache refresh continue; } @@ -390,7 +394,7 @@ void EventPoller::runLoop(bool blocked, bool ref_self) { } callback_list.for_each([this](Poll_Record::Ptr &record) { - if (this->_event_cache_expired_map[record->fd]) { + if (this->_event_cache_expired_map.find(record->fd) != this->_event_cache_expired_map.end()) { //event cache refresh return; } @@ -464,10 +468,6 @@ EventPoller::DelayTask::Ptr EventPoller::doDelayTask(uint64_t delay_ms, function return ret; } -void EventPoller::refreshEventCache(int fd) { - _event_cache_expired_map[fd] = true; - return; -} /////////////////////////////////////////////// diff --git a/src/Poller/EventPoller.h b/src/Poller/EventPoller.h index 93f26e4b..b566276e 100644 --- a/src/Poller/EventPoller.h +++ b/src/Poller/EventPoller.h @@ -178,11 +178,6 @@ class EventPoller : public TaskExecutor, public AnyStorage, public std::enable_s */ void addEventPipe(); - /** - * 删除过时的事件缓存 - */ - void refreshEventCache(int fd); - private: class ExitException : public std::exception {};