From 0ee7574732a06e8cace4e099a678f4bd5dbff679 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Fri, 13 Oct 2017 16:07:13 -0700 Subject: Removing instances of exec_ctx being passed around in functions in src/core. exec_ctx is now a thread_local pointer of type ExecCtx instead of grpc_exec_ctx which is initialized whenever ExecCtx is instantiated. ExecCtx also keeps track of the previous exec_ctx so that nesting of exec_ctx is allowed. This means that there is only one exec_ctx being used at any time. Also, grpc_exec_ctx_finish is called in the destructor of the object, and the previous exec_ctx is restored to avoid breaking current functionality. The code still explicitly calls grpc_exec_ctx_finish because removing all such instances causes the code to break. --- src/core/lib/iomgr/tcp_client_posix.cc | 63 ++++++++++++++++------------------ 1 file changed, 29 insertions(+), 34 deletions(-) (limited to 'src/core/lib/iomgr/tcp_client_posix.cc') diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc index 5611dd9062..c231c3f619 100644 --- a/src/core/lib/iomgr/tcp_client_posix.cc +++ b/src/core/lib/iomgr/tcp_client_posix.cc @@ -96,7 +96,7 @@ done: return err; } -static void tc_on_alarm(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) { +static void tc_on_alarm(void *acp, grpc_error *error) { int done; async_connect *ac = (async_connect *)acp; if (GRPC_TRACER_ON(grpc_tcp_trace)) { @@ -106,26 +106,25 @@ static void tc_on_alarm(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) { } gpr_mu_lock(&ac->mu); if (ac->fd != NULL) { - grpc_fd_shutdown(exec_ctx, ac->fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "connect() timed out")); + grpc_fd_shutdown( + ac->fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("connect() timed out")); } done = (--ac->refs == 0); gpr_mu_unlock(&ac->mu); if (done) { gpr_mu_destroy(&ac->mu); gpr_free(ac->addr_str); - grpc_channel_args_destroy(exec_ctx, ac->channel_args); + grpc_channel_args_destroy(ac->channel_args); gpr_free(ac); } } grpc_endpoint *grpc_tcp_client_create_from_fd( - grpc_exec_ctx *exec_ctx, grpc_fd *fd, const grpc_channel_args *channel_args, - const char *addr_str) { - return grpc_tcp_create(exec_ctx, fd, channel_args, addr_str); + grpc_fd *fd, const grpc_channel_args *channel_args, const char *addr_str) { + return grpc_tcp_create(fd, channel_args, addr_str); } -static void on_writable(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) { +static void on_writable(void *acp, grpc_error *error) { async_connect *ac = (async_connect *)acp; int so_error = 0; socklen_t so_error_size; @@ -149,7 +148,7 @@ static void on_writable(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) { ac->fd = NULL; gpr_mu_unlock(&ac->mu); - grpc_timer_cancel(exec_ctx, &ac->alarm); + grpc_timer_cancel(&ac->alarm); gpr_mu_lock(&ac->mu); if (error != GRPC_ERROR_NONE) { @@ -171,9 +170,8 @@ static void on_writable(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) { switch (so_error) { case 0: - grpc_pollset_set_del_fd(exec_ctx, ac->interested_parties, fd); - *ep = grpc_tcp_client_create_from_fd(exec_ctx, fd, ac->channel_args, - ac->addr_str); + grpc_pollset_set_del_fd(ac->interested_parties, fd); + *ep = grpc_tcp_client_create_from_fd(fd, ac->channel_args, ac->addr_str); fd = NULL; break; case ENOBUFS: @@ -193,7 +191,7 @@ static void on_writable(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) { don't do that! */ gpr_log(GPR_ERROR, "kernel out of buffers"); gpr_mu_unlock(&ac->mu); - grpc_fd_notify_on_write(exec_ctx, fd, &ac->write_closure); + grpc_fd_notify_on_write(fd, &ac->write_closure); return; case ECONNREFUSED: /* This error shouldn't happen for anything other than connect(). */ @@ -208,8 +206,8 @@ static void on_writable(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) { finish: if (fd != NULL) { - grpc_pollset_set_del_fd(exec_ctx, ac->interested_parties, fd); - grpc_fd_orphan(exec_ctx, fd, NULL, NULL, false /* already_closed */, + grpc_pollset_set_del_fd(ac->interested_parties, fd); + grpc_fd_orphan(fd, NULL, NULL, false /* already_closed */, "tcp_client_orphan"); fd = NULL; } @@ -232,14 +230,13 @@ finish: if (done) { gpr_mu_destroy(&ac->mu); gpr_free(ac->addr_str); - grpc_channel_args_destroy(exec_ctx, ac->channel_args); + grpc_channel_args_destroy(ac->channel_args); gpr_free(ac); } - GRPC_CLOSURE_SCHED(exec_ctx, closure, error); + GRPC_CLOSURE_SCHED(closure, error); } -static void tcp_client_connect_impl(grpc_exec_ctx *exec_ctx, - grpc_closure *closure, grpc_endpoint **ep, +static void tcp_client_connect_impl(grpc_closure *closure, grpc_endpoint **ep, grpc_pollset_set *interested_parties, const grpc_channel_args *channel_args, const grpc_resolved_address *addr, @@ -264,7 +261,7 @@ static void tcp_client_connect_impl(grpc_exec_ctx *exec_ctx, error = grpc_create_dualstack_socket(addr, SOCK_STREAM, 0, &dsmode, &fd); if (error != GRPC_ERROR_NONE) { - GRPC_CLOSURE_SCHED(exec_ctx, closure, error); + GRPC_CLOSURE_SCHED(closure, error); return; } if (dsmode == GRPC_DSMODE_IPV4) { @@ -273,7 +270,7 @@ static void tcp_client_connect_impl(grpc_exec_ctx *exec_ctx, addr = &addr4_copy; } if ((error = prepare_socket(addr, fd, channel_args)) != GRPC_ERROR_NONE) { - GRPC_CLOSURE_SCHED(exec_ctx, closure, error); + GRPC_CLOSURE_SCHED(closure, error); return; } @@ -289,20 +286,19 @@ static void tcp_client_connect_impl(grpc_exec_ctx *exec_ctx, fdobj = grpc_fd_create(fd, name); if (err >= 0) { - *ep = - grpc_tcp_client_create_from_fd(exec_ctx, fdobj, channel_args, addr_str); - GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); + *ep = grpc_tcp_client_create_from_fd(fdobj, channel_args, addr_str); + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); goto done; } if (errno != EWOULDBLOCK && errno != EINPROGRESS) { - grpc_fd_orphan(exec_ctx, fdobj, NULL, NULL, false /* already_closed */, + grpc_fd_orphan(fdobj, NULL, NULL, false /* already_closed */, "tcp_client_connect_error"); - GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_OS_ERROR(errno, "connect")); + GRPC_CLOSURE_SCHED(closure, GRPC_OS_ERROR(errno, "connect")); goto done; } - grpc_pollset_set_add_fd(exec_ctx, interested_parties, fdobj); + grpc_pollset_set_add_fd(interested_parties, fdobj); ac = (async_connect *)gpr_malloc(sizeof(async_connect)); ac->closure = closure; @@ -324,8 +320,8 @@ static void tcp_client_connect_impl(grpc_exec_ctx *exec_ctx, gpr_mu_lock(&ac->mu); GRPC_CLOSURE_INIT(&ac->on_alarm, tc_on_alarm, ac, grpc_schedule_on_exec_ctx); - grpc_timer_init(exec_ctx, &ac->alarm, deadline, &ac->on_alarm); - grpc_fd_notify_on_write(exec_ctx, ac->fd, &ac->write_closure); + grpc_timer_init(&ac->alarm, deadline, &ac->on_alarm); + grpc_fd_notify_on_write(ac->fd, &ac->write_closure); gpr_mu_unlock(&ac->mu); done: @@ -336,20 +332,19 @@ done: // overridden by api_fuzzer.c extern "C" { void (*grpc_tcp_client_connect_impl)( - grpc_exec_ctx *exec_ctx, grpc_closure *closure, grpc_endpoint **ep, + grpc_closure *closure, grpc_endpoint **ep, grpc_pollset_set *interested_parties, const grpc_channel_args *channel_args, const grpc_resolved_address *addr, grpc_millis deadline) = tcp_client_connect_impl; } -void grpc_tcp_client_connect(grpc_exec_ctx *exec_ctx, grpc_closure *closure, - grpc_endpoint **ep, +void grpc_tcp_client_connect(grpc_closure *closure, grpc_endpoint **ep, grpc_pollset_set *interested_parties, const grpc_channel_args *channel_args, const grpc_resolved_address *addr, grpc_millis deadline) { - grpc_tcp_client_connect_impl(exec_ctx, closure, ep, interested_parties, - channel_args, addr, deadline); + grpc_tcp_client_connect_impl(closure, ep, interested_parties, channel_args, + addr, deadline); } #endif -- cgit v1.2.3