diff --git a/src/core/lib/iomgr/ev_epoll_linux.c b/src/core/lib/iomgr/ev_epoll_linux.c index 249bc987356..ad1cfc20312 100644 --- a/src/core/lib/iomgr/ev_epoll_linux.c +++ b/src/core/lib/iomgr/ev_epoll_linux.c @@ -1892,7 +1892,7 @@ const grpc_event_engine_vtable *grpc_init_epoll_linux(void) { return NULL; } - if (!grpc_has_wakeup_fd) { + if (!grpc_has_wakeup_fd()) { return NULL; } diff --git a/src/core/lib/iomgr/ev_poll_cv_posix.c b/src/core/lib/iomgr/ev_poll_cv_posix.c index 1ea811e445b..0cb414ba882 100644 --- a/src/core/lib/iomgr/ev_poll_cv_posix.c +++ b/src/core/lib/iomgr/ev_poll_cv_posix.c @@ -255,21 +255,12 @@ static void shutdown_engine(void) { } const grpc_event_engine_vtable* grpc_init_poll_cv_posix(void) { - int has_wakeup_fd = grpc_has_wakeup_fd; - int allow_specialized_wakeup_fd = grpc_allow_specialized_wakeup_fd; - int allow_pipe_wakeup_fd = grpc_allow_pipe_wakeup_fd; grpc_global_cv_fd_table_init(); - grpc_allow_specialized_wakeup_fd = 0; - grpc_allow_pipe_wakeup_fd = 0; - grpc_wakeup_fd_global_init(); - grpc_has_wakeup_fd = 1; + grpc_enable_cv_wakeup_fds(1); ev_poll_vtable = grpc_init_poll_posix(); if (!ev_poll_vtable) { grpc_global_cv_fd_table_shutdown(); - grpc_has_wakeup_fd = has_wakeup_fd; - grpc_allow_specialized_wakeup_fd = allow_specialized_wakeup_fd; - grpc_allow_pipe_wakeup_fd = allow_pipe_wakeup_fd; - grpc_global_cv_fd_table_init(); + grpc_enable_cv_wakeup_fds(0); return NULL; } vtable = *ev_poll_vtable; diff --git a/src/core/lib/iomgr/ev_poll_posix.c b/src/core/lib/iomgr/ev_poll_posix.c index 97e71d968e5..0dca51bc784 100644 --- a/src/core/lib/iomgr/ev_poll_posix.c +++ b/src/core/lib/iomgr/ev_poll_posix.c @@ -1277,7 +1277,7 @@ static const grpc_event_engine_vtable vtable = { }; const grpc_event_engine_vtable *grpc_init_poll_posix(void) { - if (!grpc_has_wakeup_fd) { + if (!grpc_has_wakeup_fd()) { return NULL; } if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) { diff --git a/src/core/lib/iomgr/wakeup_fd_posix.c b/src/core/lib/iomgr/wakeup_fd_posix.c index 041c221de39..f75ae78c227 100644 --- a/src/core/lib/iomgr/wakeup_fd_posix.c +++ b/src/core/lib/iomgr/wakeup_fd_posix.c @@ -41,9 +41,11 @@ #include "src/core/lib/iomgr/wakeup_fd_posix.h" static const grpc_wakeup_fd_vtable *wakeup_fd_vtable = NULL; + int grpc_allow_specialized_wakeup_fd = 1; int grpc_allow_pipe_wakeup_fd = 1; -int grpc_has_wakeup_fd = 1; +int grpc_has_real_wakeup_fd = 1; +int grpc_cv_wakeup_fds_enabled = 0; void grpc_wakeup_fd_global_init(void) { if (grpc_allow_specialized_wakeup_fd && @@ -53,27 +55,47 @@ void grpc_wakeup_fd_global_init(void) { grpc_pipe_wakeup_fd_vtable.check_availability()) { wakeup_fd_vtable = &grpc_pipe_wakeup_fd_vtable; } else { - grpc_has_wakeup_fd = 0; - wakeup_fd_vtable = &grpc_cv_wakeup_fd_vtable; + grpc_has_real_wakeup_fd = 0; } } void grpc_wakeup_fd_global_destroy(void) { wakeup_fd_vtable = NULL; } +int grpc_has_wakeup_fd(void) { + return grpc_has_real_wakeup_fd || grpc_cv_wakeup_fds_enabled; +} + +void grpc_enable_cv_wakeup_fds(int enable) { + grpc_cv_wakeup_fds_enabled = enable; +} + grpc_error *grpc_wakeup_fd_init(grpc_wakeup_fd *fd_info) { + if (grpc_cv_wakeup_fds_enabled) { + return grpc_cv_wakeup_fd_vtable.init(fd_info); + } return wakeup_fd_vtable->init(fd_info); } grpc_error *grpc_wakeup_fd_consume_wakeup(grpc_wakeup_fd *fd_info) { + if (grpc_cv_wakeup_fds_enabled) { + return grpc_cv_wakeup_fd_vtable.consume(fd_info); + } return wakeup_fd_vtable->consume(fd_info); } grpc_error *grpc_wakeup_fd_wakeup(grpc_wakeup_fd *fd_info) { + if (grpc_cv_wakeup_fds_enabled) { + return grpc_cv_wakeup_fd_vtable.wakeup(fd_info); + } return wakeup_fd_vtable->wakeup(fd_info); } void grpc_wakeup_fd_destroy(grpc_wakeup_fd *fd_info) { - wakeup_fd_vtable->destroy(fd_info); + if (grpc_cv_wakeup_fds_enabled) { + grpc_cv_wakeup_fd_vtable.destroy(fd_info); + } else { + wakeup_fd_vtable->destroy(fd_info); + } } #endif /* GPR_POSIX_WAKEUP_FD */ diff --git a/src/core/lib/iomgr/wakeup_fd_posix.h b/src/core/lib/iomgr/wakeup_fd_posix.h index bd0fb46da1f..243c4527515 100644 --- a/src/core/lib/iomgr/wakeup_fd_posix.h +++ b/src/core/lib/iomgr/wakeup_fd_posix.h @@ -71,6 +71,9 @@ void grpc_wakeup_fd_global_destroy(void); * purposes only.*/ void grpc_wakeup_fd_global_init_force_fallback(void); +int grpc_has_wakeup_fd(void); +void grpc_enable_cv_wakeup_fds(int enable); + typedef struct grpc_wakeup_fd grpc_wakeup_fd; typedef struct grpc_wakeup_fd_vtable { @@ -89,7 +92,7 @@ struct grpc_wakeup_fd { extern int grpc_allow_specialized_wakeup_fd; extern int grpc_allow_pipe_wakeup_fd; -extern int grpc_has_wakeup_fd; +extern int grpc_has_real_wakeup_fd; #define GRPC_WAKEUP_FD_GET_READ_FD(fd_info) ((fd_info)->read_fd)