Skip to content

Commit

Permalink
优化对event_cache_expired_map 插入和查询不合理的实现 (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
baigao-X authored Jan 4, 2024
1 parent e6a32b7 commit 2167345
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
20 changes: 10 additions & 10 deletions src/Poller/EventPoller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

}

//跨线程操作
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

///////////////////////////////////////////////

Expand Down
5 changes: 0 additions & 5 deletions src/Poller/EventPoller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};

Expand Down

0 comments on commit 2167345

Please sign in to comment.