Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化对event_cache_expired_map 插入和查询不合理的实现 #203

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading