From b2e7a2848fa25f0266f88aaba0ac472c9c641b92 Mon Sep 17 00:00:00 2001 From: Jan Vidar Krey Date: Sat, 23 Jan 2010 00:03:45 +0100 Subject: [PATCH] Optimize epoll to never modify the epoll mask unless it actually changed. --- src/network/epoll.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/network/epoll.c b/src/network/epoll.c index 00ac494..0726b77 100644 --- a/src/network/epoll.c +++ b/src/network/epoll.c @@ -186,10 +186,14 @@ void net_con_reinitialize(struct net_connection* con, net_connection_cb callback void net_con_update(struct net_connection* con_, int events) { struct net_connection_epoll* con = (struct net_connection_epoll*) con_; - con->ev.events = 0; - if (events & NET_EVENT_READ) con->ev.events |= EPOLLIN; - if (events & NET_EVENT_WRITE) con->ev.events |= EPOLLOUT; + int newev = 0; + if (events & NET_EVENT_READ) newev |= EPOLLIN; + if (events & NET_EVENT_WRITE) newev |= EPOLLOUT; + if (newev == con->ev.events) + return; + + con->ev.events = newev; if (epoll_ctl(g_backend->epfd, EPOLL_CTL_MOD, con->sd, &con->ev) == -1) { LOG_TRACE("epoll_ctl() modify failed.");