#include <grpc/support/port_platform.h>
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/crash.h"
#include "src/core/lib/iomgr/port.h"
#ifdef GRPC_LINUX_EPOLL
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <poll.h>
#include <pthread.h>
#include <string.h>
#include <sys/epoll.h>
#include <sys/socket.h>
#include <unistd.h>
#include <string>
#include <vector>
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_join.h"
#include <grpc/support/alloc.h>
#include <grpc/support/cpu.h>
#include "src/core/lib/debug/stats.h"
#include "src/core/lib/debug/stats_data.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/manual_constructor.h"
#include "src/core/lib/gprpp/strerror.h"
#include "src/core/lib/iomgr/block_annotate.h"
#include "src/core/lib/iomgr/ev_epoll1_linux.h"
#include "src/core/lib/iomgr/ev_posix.h"
#include "src/core/lib/iomgr/iomgr_internal.h"
#include "src/core/lib/iomgr/lockfree_event.h"
#include "src/core/lib/iomgr/wakeup_fd_posix.h"
static grpc_wakeup_fd global_wakeup_fd;
#define MAX_EPOLL_EVENTS …
#define MAX_EPOLL_EVENTS_HANDLED_PER_ITERATION …
epoll_set;
static epoll_set g_epoll_set;
static int epoll_create_and_cloexec() { … }
static bool epoll_set_init() { … }
static void epoll_set_shutdown() { … }
struct grpc_fork_fd_list { … };
struct grpc_fd { … };
static void fd_global_init(void);
static void fd_global_shutdown(void);
kick_state;
static const char* kick_state_string(kick_state st) { … }
struct grpc_pollset_worker { … };
#define SET_KICK_STATE(worker, kick_state) …
#define MAX_NEIGHBORHOODS …
pollset_neighborhood;
struct grpc_pollset { … };
struct grpc_pollset_set { … };
static bool append_error(grpc_error_handle* composite, grpc_error_handle error,
const char* desc) { … }
static grpc_fd* fd_freelist = …;
static gpr_mu fd_freelist_mu;
static grpc_fd* fork_fd_list_head = …;
static gpr_mu fork_fd_list_mu;
static void fd_global_init(void) { … }
static void fd_global_shutdown(void) { … }
static void fork_fd_list_add_grpc_fd(grpc_fd* fd) { … }
static void fork_fd_list_remove_grpc_fd(grpc_fd* fd) { … }
static grpc_fd* fd_create(int fd, const char* name, bool track_err) { … }
static int fd_wrapped_fd(grpc_fd* fd) { … }
static void fd_shutdown_internal(grpc_fd* fd, grpc_error_handle why,
bool releasing_fd) { … }
static void fd_shutdown(grpc_fd* fd, grpc_error_handle why) { … }
static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd,
const char* reason) { … }
static bool fd_is_shutdown(grpc_fd* fd) { … }
static void fd_notify_on_read(grpc_fd* fd, grpc_closure* closure) { … }
static void fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) { … }
static void fd_notify_on_error(grpc_fd* fd, grpc_closure* closure) { … }
static void fd_become_readable(grpc_fd* fd) { … }
static void fd_become_writable(grpc_fd* fd) { … }
static void fd_has_errors(grpc_fd* fd) { … }
static void fd_set_pre_allocated(grpc_fd* fd) { … }
static thread_local grpc_pollset* g_current_thread_pollset;
static thread_local grpc_pollset_worker* g_current_thread_worker;
static gpr_atm g_active_poller;
static pollset_neighborhood* g_neighborhoods;
static size_t g_num_neighborhoods;
static bool worker_insert(grpc_pollset* pollset, grpc_pollset_worker* worker) { … }
worker_remove_result;
static worker_remove_result worker_remove(grpc_pollset* pollset,
grpc_pollset_worker* worker) { … }
static size_t choose_neighborhood(void) { … }
static grpc_error_handle pollset_global_init(void) { … }
static void pollset_global_shutdown(void) { … }
static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { … }
static void pollset_destroy(grpc_pollset* pollset) { … }
static grpc_error_handle pollset_kick_all(grpc_pollset* pollset) { … }
static void pollset_maybe_finish_shutdown(grpc_pollset* pollset) { … }
static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { … }
static int poll_deadline_to_millis_timeout(grpc_core::Timestamp millis) { … }
static grpc_error_handle process_epoll_events(grpc_pollset* ) { … }
static grpc_error_handle do_epoll_wait(grpc_pollset* ps,
grpc_core::Timestamp deadline) { … }
static bool begin_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
grpc_pollset_worker** worker_hdl,
grpc_core::Timestamp deadline) { … }
static bool check_neighborhood_for_available_poller(
pollset_neighborhood* neighborhood) { … }
static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
grpc_pollset_worker** worker_hdl) { … }
static grpc_error_handle pollset_work(grpc_pollset* ps,
grpc_pollset_worker** worker_hdl,
grpc_core::Timestamp deadline) { … }
static grpc_error_handle pollset_kick(grpc_pollset* pollset,
grpc_pollset_worker* specific_worker) { … }
static void pollset_add_fd(grpc_pollset* , grpc_fd* ) { … }
static grpc_pollset_set* pollset_set_create(void) { … }
static void pollset_set_destroy(grpc_pollset_set* ) { … }
static void pollset_set_add_fd(grpc_pollset_set* , grpc_fd* ) { … }
static void pollset_set_del_fd(grpc_pollset_set* , grpc_fd* ) { … }
static void pollset_set_add_pollset(grpc_pollset_set* ,
grpc_pollset* ) { … }
static void pollset_set_del_pollset(grpc_pollset_set* ,
grpc_pollset* ) { … }
static void pollset_set_add_pollset_set(grpc_pollset_set* ,
grpc_pollset_set* ) { … }
static void pollset_set_del_pollset_set(grpc_pollset_set* ,
grpc_pollset_set* ) { … }
static bool is_any_background_poller_thread(void) { … }
static void shutdown_background_closure(void) { … }
static bool add_closure_to_background_poller(grpc_closure* ,
grpc_error_handle ) { … }
static void shutdown_engine(void) { … }
static bool init_epoll1_linux();
const grpc_event_engine_vtable grpc_ev_epoll1_posix = …;
static void reset_event_manager_on_fork() { … }
static bool init_epoll1_linux() { … }
#else
#if defined(GRPC_POSIX_SOCKET_EV_EPOLL1)
#include "src/core/lib/iomgr/ev_epoll1_linux.h"
const grpc_event_engine_vtable grpc_ev_epoll1_posix = {
1,
true,
false,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
"epoll1",
[](bool) { return false; },
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
};
#endif
#endif