From 21e360382f7f022aed6cdd2522ebc33aaf6d7436 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Tue, 5 Jun 2018 10:55:13 -0700 Subject: [PATCH] Add more detailed comments --- src/core/lib/iomgr/ev_epoll1_linux.cc | 6 ++++-- src/core/lib/iomgr/ev_posix.h | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index 356fbae1397..1c495b47bcc 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -309,7 +309,9 @@ static grpc_fd* fd_create(int fd, const char* name, bool track_err) { struct epoll_event ev; ev.events = static_cast(EPOLLIN | EPOLLOUT | EPOLLET); - /* Use the least significant bit of ev.data.ptr to store track_err. */ + /* Use the least significant bit of ev.data.ptr to store track_err. We expect + * the addresses to be word aligned. We need to store track_err to avoid + * synchronization issues when accessing it after receiving an event. */ ev.data.ptr = reinterpret_cast(reinterpret_cast(new_fd) | (track_err ? 1 : 0)); if (epoll_ctl(g_epoll_set.epfd, EPOLL_CTL_ADD, fd, &ev) != 0) { @@ -626,7 +628,7 @@ static grpc_error* process_epoll_events(grpc_pollset* pollset) { grpc_fd* fd = reinterpret_cast( reinterpret_cast(data_ptr) & ~static_cast(1)); bool track_err = - reinterpret_cast(data_ptr) & ~static_cast(1); + reinterpret_cast(data_ptr) & static_cast(1); bool cancel = (ev->events & EPOLLHUP) != 0; bool error = (ev->events & EPOLLERR) != 0; bool read_ev = (ev->events & (EPOLLIN | EPOLLPRI)) != 0; diff --git a/src/core/lib/iomgr/ev_posix.h b/src/core/lib/iomgr/ev_posix.h index 200e158dff5..e3996ce3657 100644 --- a/src/core/lib/iomgr/ev_posix.h +++ b/src/core/lib/iomgr/ev_posix.h @@ -86,7 +86,11 @@ void grpc_event_engine_shutdown(void); /* Return the name of the poll strategy */ const char* grpc_get_poll_strategy_name(); -/* Returns true if polling engine can track errors separately, false otherwise +/* Returns true if polling engine can track errors separately, false otherwise. + * If this is true, fd can be created with track_err set. After this, error + * events will be reported using fd_notify_on_error. If it is not set, errors + * will continue to be reported through fd_notify_on_read and + * fd_notify_on_write. */ bool grpc_event_engine_can_track_errors();