From 49959ed9c1e06a8d5aa6e0bd077fd940dfc3741d Mon Sep 17 00:00:00 2001 From: David Klempner Date: Tue, 10 Feb 2015 18:48:48 -0800 Subject: [PATCH] Have unary pollset check to see if the existing fd is orphaned This avoids an unnecessary upgrade to multipoller if there was no do_work called between an orphan and a subsequent add. Additionally, it avoids the need for epoll based multipoller to check for this case in its upgrade code by ensuring all existing fds are valid at upgrade time. --- src/core/iomgr/pollset_posix.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c index b0404b870b5..2837a0dff3f 100644 --- a/src/core/iomgr/pollset_posix.c +++ b/src/core/iomgr/pollset_posix.c @@ -202,8 +202,15 @@ static void unary_poll_pollset_add_fd(grpc_pollset *pollset, grpc_fd *fd) { if (fd == pollset->data.ptr) return; fds[0] = pollset->data.ptr; fds[1] = fd; - grpc_platform_become_multipoller(pollset, fds, GPR_ARRAY_SIZE(fds)); - grpc_fd_unref(fds[0]); + if (!grpc_fd_is_orphaned(fds[0])) { + grpc_platform_become_multipoller(pollset, fds, GPR_ARRAY_SIZE(fds)); + grpc_fd_unref(fds[0]); + } else { + /* old fd is orphaned and we haven't cleaned it up until now, so remain a + * unary poller */ + grpc_fd_unref(fds[0]); + pollset->data.ptr = fd; + } } static void unary_poll_pollset_del_fd(grpc_pollset *pollset, grpc_fd *fd) {